Jenkins 安装

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
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 219,270评论 6 508
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,489评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 165,630评论 0 356
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,906评论 1 295
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,928评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,718评论 1 305
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,442评论 3 420
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,345评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,802评论 1 317
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,984评论 3 337
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,117评论 1 351
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,810评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,462评论 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,011评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,139评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,377评论 3 373
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,060评论 2 355

推荐阅读更多精彩内容