Jenkins安装

来自ling
跳转至: 导航搜索

自动化部署脚本参考

安装

Docker常用服务#Jenkins

 docker run --name jenkins --restart=always -p 71:8080 -p 50000:50000 -v /alidata/dockerdata/jenkins/data:/var/jenkins_home \
-v /alidata/server/maven_repository:/var/jenkins_home/.m2 \
-v /alidata/server/maven3.5.0:/alidata/server/maven3.5.0 \
-v /alidata/server/java:/alidata/server/java \
-d jenkins

https://github.com/jenkinsci/docker/blob/master/README.md

docker run --name jenkins --restart=always -p 71:8080 -p 50000:50000 -v /alidata/dockerdata/jenkins/data:/var/jenkins_home \
-v /alidata/server/maven_repository:/var/jenkins_home/.m2 \
-v /alidata/server/apache-maven-3.8.3:/alidata/server/apache-maven-3.8.3 \
-v /alidata/server/java:/alidata/server/java \
-d jenkins/jenkins:lts
docker cp jenkins:/var/jenkins_home/secrets/initialAdminPassword /alidata/dockerdata/jenkins
cd /alidata/server
sudo wget wget https://mirrors.cnnic.cn/apache/maven/maven-3/3.8.3/binaries/apache-maven-3.8.3-bin.tar.gz
tar -zxvf apache-maven-3.8.3-bin.tar.gz
vi /etc/profile

以下代码下添加export

unset i
unset -f pathmunge
export MAVEN_HOME=/alidata/server/apache-maven-3.8.3
export PATH=$MAVEN_HOME/bin:$PATH

编译生效

source /etc/profile
. /etc/profile
mvn -version
百度网盘下载jkd 上传至 /alidata/server
tar -zxvf jdk-8u91-linux-x64.tar.gz
#export JAVA_HOME=/usr/local/java/jdk1.8.0_221
export JAVA_HOME=/alidata/server/jdk1.8.0_221
export CLASSPATH=$JAVA_HOME/lib/
export PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME CLASSPATH

迁移

rm -rf /alidata/dockerdata/jenkins/data/jobs/ling-cloud-auth/builds
rm -rf /alidata/dockerdata/jenkins/data/jobs/ling-cloud-base/builds
rm -rf /alidata/dockerdata/jenkins/data/jobs/ling-cloud-common/builds
rm -rf /alidata/dockerdata/jenkins/data/jobs/ling-cloud-config/builds
rm -rf /alidata/dockerdata/jenkins/data/jobs/ling-cloud-dependency/builds
rm -rf /alidata/dockerdata/jenkins/data/jobs/ling-cloud-eureka/builds
rm -rf /alidata/dockerdata/jenkins/data/jobs/ling-cloud-gateway/builds
rm -rf /alidata/dockerdata/jenkins/data/jobs/ling-cloud-parent/builds
rm -rf /alidata/dockerdata/jenkins/data/jobs/ling-cloud-resouces/builds
rm -rf /alidata/dockerdata/jenkins/data/jobs/ling-cloud-auth/modules
rm -rf /alidata/dockerdata/jenkins/data/jobs/ling-cloud-base/modules
rm -rf /alidata/dockerdata/jenkins/data/jobs/ling-cloud-common/modules
rm -rf /alidata/dockerdata/jenkins/data/jobs/ling-cloud-config/modules
rm -rf /alidata/dockerdata/jenkins/data/jobs/ling-cloud-dependency/modules
rm -rf /alidata/dockerdata/jenkins/data/jobs/ling-cloud-eureka/modules
rm -rf /alidata/dockerdata/jenkins/data/jobs/ling-cloud-gateway/modules
rm -rf /alidata/dockerdata/jenkins/data/jobs/ling-cloud-parent/modules
rm -rf /alidata/dockerdata/jenkins/data/jobs/ling-cloud-resouces/modules
rm -rf /alidata/dockerdata/jenkins/data/jobs/ling-cloud-test
rm -rf /alidata/dockerdata/jenkins/data/workspace
rm -rf /alidata/dockerdata/jenkins/data/war
rm -rf /alidata/dockerdata/jenkins/data/tools
rm -rf /alidata/dockerdata/jenkins/data/.jenkins/cache/
rm -rf /alidata/dockerdata/jenkins/data/cache/
rm -rf /alidata/dockerdata/data/fingerprints
rm -rf /alidata/dockerdata/jenkins.tar.gz
tar -zcvf /alidata/dockerdata/jenkins.tar.gz /alidata/dockerdata/jenkins
tar -zxvf /alidata/dockerdata/jenkins.tar.gz

插件

  • 手工安装
  • Git plugin
  • Maven Integration plugin
  • Publish Over SSH
  • SSH plugin
  • SSH Slaves plugin
  • SSH配置在系统配置的最下面
  • Config File Provider Plugin
  • Dashboard View

jdk

/alidata/server/java/1.8_64

maven

/alidata/server/maven3.5.0 maven必须使用3.3.9,否则问题太多,特别是不能独立编译子模块

ssh server

在系统设置最下面配置 Ssh server.PNG

top level maven配置

/var/jenkins_home/.m2/settings.xml

Jenkins maven setting file.PNG

maven setting.xml

此用法没生效,不知道为什么

mvn install -s /var/jenkins_home/.m2/settings.xml -P docker

tee /alidata/server/maven_repository/settings.xml <<-'EOF'
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">
	<localRepository>/var/jenkins_home/.m2/repository</localRepository>
	<interactiveMode>true</interactiveMode>
	<usePluginRegistry />
	<offline>false</offline>
	<pluginGroups />
	
    <servers>
        <server>
            <id>ling-releases</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
        <server>
            <id>ling-snapshots</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
    </servers>
	
	<proxies />
	<profiles>
		<profile>
			<id>jdk-1.8</id>
			<activation>
				<activeByDefault>true</activeByDefault>
				<jdk>1.8</jdk>
			</activation>
			<properties>
				<maven.compiler.source>1.8</maven.compiler.source>
				<maven.compiler.target>1.8</maven.compiler.target>
				<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
			</properties>
			<repositories>
				<!-- oschina maven -->
				<repository>
					<id>oschinaRepository</id>
					<name>local private nexus</name>
					<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
					<releases>
						<enabled>true</enabled>
					</releases>
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
				</repository>
			</repositories>
			<!-- 指定maven plugin仓库 -->
			<pluginRepositories>
				<!-- oschina的maven plugin仓库 -->
				<pluginRepository>
					<id>oschinaPluginRepository</id>
					<name>local private nexus</name>
					<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
					<releases>
						<enabled>true</enabled>
					</releases>
					<snapshots>
						<enabled>false</enabled>
					</snapshots>
				</pluginRepository>
			</pluginRepositories>
		</profile>  
	</profiles>
</settings>
EOF


群辉

tee /alidata/server/apache-maven-3.6.3/conf/settings.xml <<-'EOF'
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>/alidata/server/maven_repository/repository</localRepository>
<interactiveMode>true</interactiveMode>
<usePluginRegistry />
<offline>false</offline>
<pluginGroups />

    <servers>
        <server>
            <id>ling-releases</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
        <server>
            <id>ling-snapshots</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
    </servers>

<proxies />
<profiles>
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
<repositories>
<!-- oschina maven -->
<repository>
<id>oschinaRepository</id>
<name>local private nexus</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<!-- 指定maven plugin仓库 -->
<pluginRepositories>
<!-- oschina的maven plugin仓库 -->
<pluginRepository>
<id>oschinaPluginRepository</id>
<name>local private nexus</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>  
</profiles>
</settings>

EOF

问题解决

忘记密码

bo.wang/Wb191010610109

https://www.jianshu.com/p/670a7a52af14

No valid crumb was included in the request

在jenkins 的Configure Global Security下 , 取消“防止跨站点请求伪造(Prevent Cross Site Request Forgery exploits)”的勾选。(如下图)

Executing Maven: -N -B -f java.lang.NullPointerException

at jenkins.maven3.agent.Maven33Main.launch(Maven33Main.java:176)

通过排查暂时可以这样解决:jenkins的全局工具中maven的版本不是使用3.5,需要修改成3.3.9就可以了。

docker put 主机过慢

仅限于Jenkins传递文件到宿主机.

使用ifconfig后使用下面的ip,

Jenkins-docker-ssh-master-slow.PNG