Jenkins 安装
版本:Jenkins 2.301
开启端口
firewall-cmd --zone=public --add-port=8080/tcp --permanent
#刷新防火墙
firewall-cmd --reload
下载安装tomcat
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key
yum install jenkins
jenkins相关目录释义:
(1)/usr/lib/jenkins/:jenkins安装目录,war包会放在这里。
(2)/etc/sysconfig/jenkins:jenkins配置文件,“端口”,“JENKINS_HOME”等都可以在这里配置。
(3)/var/lib/jenkins/:默认的JENKINS_HOME。
(4)/var/log/jenkins/jenkins.log:jenkins日志文件。
问题处理
find / -name hudson.model.UpdateCenter.xml
将 url 中的 https://updates.jenkins.io/update-center.json 更改为
vim /var/lib/jenkins/hudson.model.UpdateCenter.xml
<?xml version='1.1' encoding='UTF-8'?>
<sites>
<site>
<id>default</id>
<url>http://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json</url>
</site>
</sites>
~
重启即可
解锁 Jenkins
为了确保管理员安全地安装 Jenkins,密码已写入到日志中(不知道在哪里?)该文件在服务器上:
/var/lib/jenkins/secrets/initialAdminPassword
请从本地复制密码并粘贴到下面。
管理员密码
[root@itdev9901 bin]# cat /var/lib/jenkins/secrets/initialAdminPassword
85e9e517a5ac43b9b0b0650e733a7463
[root@itdev9901 bin]#
安装插件不成功
# 修改前备份
cd /var/lib/jenkins/updates
cp default.json default.json.bak
# 修改default.json文件
sed -i 's#https://updates.jenkins.io/download#http://mirrors.tuna.tsinghua.edu.cn/jenkins#g' default.json
sed -i 's#http://www.google.com#http://www.baidu.com#g' default.json
修改镜像后重启 ,插件即可安装成功
[root@itdev9901 updates]# systemctl restart jenkins
[root@itdev9901 updates]#
2021-07-12 04:48:33.810+0000 [id=15] INFO hudson.PluginManager#install: Starting installation of a batch of 1 plugins plus their dependencies
2021-07-12 04:48:33.811+0000 [id=15] INFO hudson.model.UpdateSite$Plugin#deploy: Adding dependent install of display-url-api for plugin mailer
2021-07-12 04:48:33.811+0000 [id=15] INFO hudson.model.UpdateSite$Plugin#deploy: Adding dependent install of trilead-api for plugin display-url-api
2021-07-12 04:48:33.811+0000 [id=15] INFO hudson.model.UpdateSite$Plugin#deploy: Adding dependent install of sshd for plugin trilead-api
2021-07-12 04:48:34.265+0000 [id=62] INFO h.model.UpdateCenter$DownloadJob#run: Starting the installation of sshd on behalf of admin
2021-07-12 04:48:34.423+0000 [id=62] INFO h.m.UpdateCenter$UpdateCenterConfiguration#download: Downloading sshd
2021-07-12 04:48:36.548+0000 [id=62] INFO h.model.UpdateCenter$DownloadJob#run: Installation successful: sshd
2021-07-12 04:48:36.548+0000 [id=62] INFO h.model.UpdateCenter$DownloadJob#run: Starting the installation of trilead-api on behalf of admin
2021-07-12 04:48:36.608+0000 [id=62] INFO h.m.UpdateCenter$UpdateCenterConfiguration#download: Downloading trilead-api
2021-07-12 04:48:38.887+0000 [id=62] INFO h.model.UpdateCenter$DownloadJob#run: Installation successful: trilead-api
2021-07-12 04:48:38.887+0000 [id=62] INFO h.model.UpdateCenter$DownloadJob#run: Starting the installation of display-url-api on behalf of admin
2021-07-12 04:48:38.952+0000 [id=62] INFO h.m.UpdateCenter$UpdateCenterConfiguration#download: Downloading display-url-api
2021-07-12 04:48:38.977+0000 [id=62] INFO h.model.UpdateCenter$DownloadJob#run: Installation successful: display-url-api
2021-07-12 04:48:38.977+0000 [id=62] INFO h.model.UpdateCenter$DownloadJob#run: Starting the installation of mailer on behalf of admin
2021-07-12 04:48:39.043+0000 [id=62] INFO h.m.UpdateCenter$UpdateCenterConfiguration#download: Downloading mailer
2021-07-12 04:48:39.188+0000 [id=62] INFO h.model.UpdateCenter$DownloadJob#run: Installation successful: mailer
2021-07-12 04:48:39.188+0000 [id=62] INFO h.m.UpdateCenter$CompleteBatchJob#run: Completing installing of plugin batch…
2021-07-12 04:48:39.329+0000 [id=65] INFO jenkins.InitReactorRunner$1#onAttained: Started initialization
2021-07-12 04:48:39.330+0000 [id=66] INFO jenkins.InitReactorRunner$1#onAttained: Listed all plugins
2021-07-12 04:48:39.330+0000 [id=66] INFO jenkins.InitReactorRunner$1#onAttained: Prepared all plugins
2021-07-12 04:48:39.331+0000 [id=66] INFO jenkins.InitReactorRunner$1#onAttained: Started all plugins
2021-07-12 04:48:39.331+0000 [id=66] INFO jenkins.InitReactorRunner$1#onAttained: Augmented all extensions
2021-07-12 04:48:39.331+0000 [id=66] INFO jenkins.InitReactorRunner$1#onAttained: System config loaded
2021-07-12 04:48:39.331+0000 [id=66] INFO jenkins.InitReactorRunner$1#onAttained: System config adapted
2021-07-12 04:48:39.331+0000 [id=66] INFO jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
2021-07-12 04:48:39.331+0000 [id=65] INFO jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated
2021-07-12 04:48:39.334+0000 [id=66] INFO jenkins.InitReactorRunner$1#onAttained: Completed initialization
2021-07-12 04:48:39.334+0000 [id=62] INFO h.m.UpdateCenter$CompleteBatchJob#run: Completed installation of 4 plugins in 5.5 sec
日志监听
[root@itdev9901 ~]# tail -f /var/log/jenkins/jenkins.log
2021-07-12 05:31:20.820+0000 [id=89] INFO h.model.UpdateCenter$DownloadJob#run: Installation successful: jobConfigHistory
2021-07-12 05:31:20.820+0000 [id=89] INFO h.model.UpdateCenter$DownloadJob#run: Starting the installation of cvs on behalf of admin
2021-07-12 05:31:20.879+0000 [id=89] INFO h.m.UpdateCenter$UpdateCenterConfiguration#download: Downloading cvs
2021-07-12 05:31:21.837+0000 [id=89] INFO h.model.UpdateCenter$DownloadJob#run: Installation successful: cvs
2021-07-12 05:31:21.837+0000 [id=89] INFO h.model.UpdateCenter$DownloadJob#run: Starting the installation of nodejs on behalf of admin
2021-07-12 05:31:21.897+0000 [id=89] INFO h.m.UpdateCenter$UpdateCenterConfiguration#download: Downloading nodejs
2021-07-12 05:31:21.973+0000 [id=89] INFO h.model.UpdateCenter$DownloadJob#run: Installation successful: nodejs
2021-07-12 05:31:21.973+0000 [id=89] INFO h.model.UpdateCenter$DownloadJob#run: Starting the installation of aws-java-sdk on behalf of admin
2021-07-12 05:31:22.048+0000 [id=89] INFO h.m.UpdateCenter$UpdateCenterConfiguration#download: Downloading aws-java-sdk
2021-07-12 05:31:31.183+0000 [id=15] INFO hudson.model.UpdateCenter#doSafeRestart: Scheduling Jenkins reboot
jenkins 配置 gogos
# 生成密钥
ssh-keygen -t rsa -b 4096 -C "邮件@xxx.com"
设置推送地址
推送地址的格式为:http(s)://<你的Jenkins地址>/gogs-webhook/?job=<你的Jenkins任务名>
http://172.18.5.127:8080/gogs-webhook/?job=omo-jk-demo
指定分支:refs/heads/develop
sonar令牌
https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/
mvn clean verify sonar:sonar -Dsonar.login=53c44917a2ce56328452777c8ed5b325aac8a950 -Dmaven.test.skip=true -Dsonar.branch.name=master
mvn clean verify sonar:sonar -Dsonar.login=53c44917a2ce56328452777c8ed5b325aac8a950 -Dmaven.test.skip=true -Dsonar.branch.name=develop
# jenkins 设置 projectName,projectKey 为 job 名称
# job 名称规范: 工程名称-分支名称
$ clean verify sonar:sonar -Dmaven.test.skip=true -Dsonar.projectName=${JOB_NAME} -Dsonar.projectKey=${JOB_NAME}
配置
sonar.projectKey=omo-jk-demo
sonar.language=java
sonar.java.source=1.8
sonar.projectName=omo-jk-demo
sonar.projectVersion=1.0
sonar.pullrequest.key = 100
sonar.pullrequest.branch = develop
sonar.pullrequest.base = master
# 首次构建去掉
sonar.branch.name=develop
------------------------------------------
# project属性
sonar.projectKey=${JOB_NAME}
sonar.projectName=${JOB_NAME}
sonar.projectVersion=${BUILD_ID}
--------------------------------------------
#projectKey项目的唯一标识,不能重复
sonar.projectKey=insurance-view
sonar.projectName=insurance-view
sonar.projectVersion=1.0
sonar.sourceEncoding=UTF-8
sonar.modules=javascript-module
# JavaScript module
javascript-module.sonar.projectName=JavaScript Module
javascript-module.sonar.language=js
javascript-module.sonar.sources=.
javascript-module.sonar.projectBaseDir=src
----------------------
sonar.projectKey=${JOB_NAME}
sonar.projectName=${JOB_NAME}
sonar.projectVersion=${BUILD_ID}
sonar.sourceEncoding=UTF-8
sonar.language=js
sonar.sources=src/
jenkins 迁移
# 1. 迁移文件
scp -r /etc/sysconfig/jenkins/ 172.18.5.124:/etc/sysconfig/jenkins
scp -r /usr/lib/jenkins/ 172.18.5.124:/usr/lib/jenkins
scp -r /var/lib/jenkins/ 172.18.5.124:/var/lib/jenkins
chown -R jenkins:jenkins /var/lib/jenkins/
# 2. 添加启动用户
useradd -d /var/lib/jenkins -c 'Jenkins Automation Server' jenkins -s /bin/false
# 3.拷贝启动文件
scp -r /etc/rc.d/init.d/jenkins 172.18.5.124:/etc/rc.d/init.d/
# 查找admin密码
cat /var/lib/jenkins/secrets/initialAdminPassword
# 调试启动
java -DJENKINS_HOME=/var/lib/jenkins -jar jenkins.war
网友评论