jenkins
概述
https://www.jenkins.io/doc/book/installing/linux/#red-hat-centos Jenkins是一個(gè)開源的囚玫、提供友好操作界面的持續(xù)集成(CI)工具,起源于Hudson(Hudson是商用的)颈渊,主要用于持續(xù)、自動(dòng)的構(gòu)建/測(cè)試軟件項(xiàng)目场斑、監(jiān)控外部任務(wù)的運(yùn)行(這個(gè)比較抽象蛔溃,暫且寫上,不做解釋)云挟。Jenkins用Java語言編寫矫限,可在Tomcat等流行的servlet容器中運(yùn)行哺哼,也可獨(dú)立運(yùn)行。通常與版本管理工具(SCM)叼风、構(gòu)建工具結(jié)合使用取董。常用的版本控制工具有SVN、GIT无宿,構(gòu)建工具有Maven茵汰、Ant、Gradle孽鸡。
安裝
把壓縮包下載到本地 linux jenkins 鏈接: https://pan.baidu.com/s/1oFifF8HSOjFrv199_36UyA 提取碼: zfyq
解壓
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="s" cid="n9" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); --select-text-bg-color: #36284e; --select-text-font-color: #fff; font-size: 0.9rem; line-height: 1.71429em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; margin-left: 2em; padding-left: 1ch; padding-right: 1ch; width: inherit; color: rgb(31, 9, 9); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">[root@VM-0-2-centos software]# ls
sonarqube-7.6 sonarqube-7.6.zip
[root@VM-0-2-centos software]# ls
jenkins-2.174-1.1.noarch.rpm sonarqube-7.6 sonarqube-7.6.zip
[root@VM-0-2-centos software]# </pre>
- 查看目錄
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="s" cid="n13" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); --select-text-bg-color: #36284e; --select-text-font-color: #fff; font-size: 0.9rem; line-height: 1.71429em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; margin-left: 2em; padding-left: 1ch; padding-right: 1ch; width: inherit; color: rgb(31, 9, 9); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">[root@VM-0-2-centos software]# rpm -ivh jenkins-2.174-1.1.noarch.rpm
warning: jenkins-2.174-1.1.noarch.rpm: Header V4 DSA/SHA1 Signature, key ID d50582e6: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:jenkins-2.174-1.1 ################################# [100%]
[root@VM-0-2-centos software]# ls
jenkins-2.174-1.1.noarch.rpm sonarqube-7.6 sonarqube-7.6.zip
[root@VM-0-2-centos software]# whereis jenkins
jenkins: /usr/lib/jenkins
[root@VM-0-2-centos software]#
</pre>
- 運(yùn)行
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="s" cid="n17" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); --select-text-bg-color: #36284e; --select-text-font-color: #fff; font-size: 0.9rem; line-height: 1.71429em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; margin-left: 2em; padding-left: 1ch; padding-right: 1ch; width: inherit; color: rgb(31, 9, 9); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">[root@VM-0-2-centos software]# cd /usr/lib/jenkins/
[root@VM-0-2-centos jenkins]# ls
jenkins.war
[root@VM-0-2-centos jenkins]# service jenkins start
Starting jenkins (via systemctl): Job for jenkins.service failed because the control process exited with error code.
See "systemctl status jenkins.service" and "journalctl -xe" for details.
[FAILED]
[root@VM-0-2-centos jenkins]#
</pre>
修改端口:http://www.reibang.com/p/28683208368c 注意:直接修改jenkins.xml中arguments的httpPort是不能真正修改端口的蹂午。
另附:關(guān)閉和重啟jenkins服務(wù)
(1)cd到j(luò)enkins的war包所在的目錄
(2)執(zhí)行命令執(zhí)行命令:“java -jar jenkins.war --ajp13Port=-1 --httpPort=8081”
(3)啟動(dòng)jenkins服務(wù):“net start jenkins”
(4)停止jenkins服務(wù):“net stop jenkins”
作者:智谷說 鏈接:http://www.reibang.com/p/28683208368c 來源:簡(jiǎn)書 著作權(quán)歸作者所有栏豺。商業(yè)轉(zhuǎn)載請(qǐng)聯(lián)系作者獲得授權(quán),非商業(yè)轉(zhuǎn)載請(qǐng)注明出處豆胸。 de1e3f3721c34aa5bb00c79eecea307e
- 報(bào)錯(cuò): 到網(wǎng)上找了下原因奥洼,是因?yàn)槲襧enkins中的沒有配置jdk的路徑; 然后修改/etc/init.d/jenkins文件
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="s" cid="n29" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); --select-text-bg-color: #36284e; --select-text-font-color: #fff; font-size: 0.9rem; line-height: 1.71429em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; margin-left: 2em; padding-left: 1ch; padding-right: 1ch; width: inherit; color: rgb(31, 9, 9); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">candidates="
/etc/alternatives/java
/usr/lib/jvm/java-1.8.0/bin/java
/usr/lib/jvm/jre-1.8.0/bin/java
/usr/lib/jvm/java-1.7.0/bin/java
/usr/lib/jvm/jre-1.7.0/bin/java
/usr/lib/jvm/java-11.0/bin/java
/usr/lib/jvm/jre-11.0/bin/java
/usr/lib/jvm/java-11-openjdk-amd64
/usr/bin/java
/usr/local/java/jdk1.8.0_161/bin/java</pre>
- 運(yùn)行成功
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="s" cid="n33" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); --select-text-bg-color: #36284e; --select-text-font-color: #fff; font-size: 0.9rem; line-height: 1.71429em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; margin-left: 2em; padding-left: 1ch; padding-right: 1ch; width: inherit; color: rgb(31, 9, 9); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">[root@VM-0-2-centos jenkins]# service jenkins start
Starting jenkins (via systemctl): Warning: The unit file, source configuration file or drop-ins of jenkins.service changed on disk. Run 'systemctl daemon-reload' to reload units.
[ OK ]</pre>
訪問一下,瀏覽器訪問:http://服務(wù)器IP:8080/ 效果:
- 查看密碼
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="s" cid="n38" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); --select-text-bg-color: #36284e; --select-text-font-color: #fff; font-size: 0.9rem; line-height: 1.71429em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; margin-left: 2em; padding-left: 1ch; padding-right: 1ch; width: inherit; color: rgb(31, 9, 9); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">[root@VM-0-2-centos jenkins]# cd /var/lib/jenkins/secrets/
[root@VM-0-2-centos secrets]# ll
total 28
drwxr-xr-x 2 jenkins jenkins 4096 Apr 13 19:20 filepath-filters.d
-rw-r----- 1 jenkins jenkins 33 Apr 13 19:20 initialAdminPassword
-rw-r--r-- 1 jenkins jenkins 32 Apr 13 19:20 jenkins.model.Jenkins.crumbSalt
-rw-r--r-- 1 jenkins jenkins 256 Apr 13 19:20 master.key
-rw-r--r-- 1 jenkins jenkins 272 Apr 13 19:20 org.jenkinsci.main.modules.instance_identity.InstanceIdentity.KEY
-rw-r--r-- 1 jenkins jenkins 5 Apr 13 19:20 slave-to-master-security-kill-switch
drwxr-xr-x 2 jenkins jenkins 4096 Apr 13 19:20 whitelisted-callables.d
[root@VM-0-2-centos secrets]# cat initialAdminPassword
4d81e0e9f15d40838b0b9e09c4e900a1
</pre>
效果:安裝推薦的插件
- 安裝插件失敗
[http://www.reibang.com/p/2b7288e77ff8]
(http://www.reibang.com/p/2b7288e77ff8)
使用
- 安裝插件 jenkins => 系統(tǒng)管理 => 插件管理 => 搜索 mavan I => 安裝失敗:
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="s" cid="n48" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); --select-text-bg-color: #36284e; --select-text-font-color: #fff; font-size: 0.9rem; line-height: 1.71429em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; margin-left: 2em; padding-left: 1ch; padding-right: 1ch; width: inherit; color: rgb(31, 9, 9); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">
失敗 -
java.io.IOException: Maven Integration plugin version 3.8 failed to load.
- You must update Jenkins from version 2.174 to version 2.204.6 or later to run this plugin.
- Jenkins JSch dependency plugin version 0.1.55.2 failed to load. Fix this plugin first.
at hudson.PluginWrapper.resolvePluginDependencies(PluginWrapper.java:868)
at hudson.PluginManager.dynamicLoad(PluginManager.java:906)
Caused: java.io.IOException: Failed to install maven-plugin plugin
at hudson.PluginManager.dynamicLoad(PluginManager.java:916)
at hudson.PluginManager.dynamicLoad(PluginManager.java:852)
at hudson.model.UpdateCenterInstallationJob._run(UpdateCenter.java:2034)
at hudson.model.UpdateCenterRunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at hudson.remoting.AtmostOneThreadExecutor$Worker.run(AtmostOneThreadExecutor.java:112)
at java.lang.Thread.run(Thread.java:748)
返回首頁(yè)</pre>
【linux安裝晚胡、卸載灵奖、自定義配置 jenkins】 https://blog.csdn.net/lijing742180/article/details/81127409?utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control 【jenkins安裝配置及插件安裝】 https://blog.csdn.net/lijing742180/article/details/86517768
https://www.cnblogs.com/mmzs/p/12092982.html
【構(gòu)建完自動(dòng)生成的目錄】
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="s" cid="n53" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); --select-text-bg-color: #36284e; --select-text-font-color: #fff; font-size: 0.9rem; line-height: 1.71429em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; margin-left: 2em; padding-left: 1ch; padding-right: 1ch; width: inherit; color: rgb(31, 9, 9); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">[root@VM-0-2-centos /]# ll /root/.jenkins/workspace/springboot-auto2/target/gzsz-shop-api-0.1.jar
-rw-r--r-- 1 root root 17345795 Sep 1 21:42 /root/.jenkins/workspace/springboot-auto2/target/gzsz-shop-api-0.1.jar</pre>
【腳本自動(dòng)化部署】
配置 => 構(gòu)建后的配置 => Archive the artifacts => */target/.jar
構(gòu)建后的地址:http://119.29.14.214:9091/job/springboot-auto2/lastSuccessfulBuild/artifact/target/gzsz-shop-api-0.1.jar
shell腳本 => [Jenkins-1]解決Jenkins使用nohup掛起線程指令顯示SUCCESS但實(shí)際上沒有執(zhí)行的問題 https://blog.csdn.net/weixin_39359455/article/details/108878865 【構(gòu)建時(shí)候jenkins拉取git代碼目錄】 /var/lib/jenkins/workspace/
使用
初始化
maven下載: https://www.cnblogs.com/shunzi115/p/12521630.html git下載: https://blog.csdn.net/xiaoye319/article/details/89642875 流程圖:
-
全局安全配置
允許用戶注冊(cè) --- 生產(chǎn)環(huán)境慎重
任何用戶可以做任何事(沒有任何限制) --- 生產(chǎn)環(huán)境慎重
-
全局工具配置
Maven 配置: /usr/src/maven/apache-maven-3.3.9/settings.xml
JDK: /usr/java/jdk1.8.0_161
GIT
Maven: /usr/src/maven/apache-maven-3.3.9/
系統(tǒng)配置:
-
插件配置:
插件1:Publish over SSH
插件2:Deploy to container Plugin
Jenkins自動(dòng)化部署(springBoot+maven+gitHub)項(xiàng)目
https://www.cnblogs.com/wfd360/p/11314697.html https://www.cnblogs.com/grey-wolf/p/8795095.html
gitlab項(xiàng)目根目錄下必須有pom文件 bug:
- ERROR: Failed to find configuration named [] check the global configuration Build step 'Send build artifacts over SSH' changed build result to UNSTABLE
Finished: UNSTABLE
- [ERROR] Error executing Maven. [ERROR] The specified user settings file does not exist: /usr/src/maven/apache-maven-3.3.9/settings.xml Build step 'Invoke top-level Maven targets' marked build as failure SSH: Current build result is [FAILURE], not going to run. Finished: FAILURE
bug:通過jenkins運(yùn)行腳本(在服務(wù)器運(yùn)行腳本沒有問題)
拉取最新git代碼,但是沒有覆蓋到指定目錄位置jar包,導(dǎo)致運(yùn)行項(xiàng)目是上一個(gè)版本的估盘。
運(yùn)行腳本后瓷患,直接把項(xiàng)目進(jìn)程殺死。
解決: 配置觸發(fā)器任務(wù): 構(gòu)建觸發(fā)器遣妥,使用輪詢SCM方式
一擅编、定時(shí)構(gòu)建:不管SVN或Git中數(shù)據(jù)有無變化,均執(zhí)行定時(shí)化的構(gòu)建任務(wù) 燥透;
二沙咏、輪詢SCM:只要SVN或Git中數(shù)據(jù)有更新辨图,則執(zhí)行構(gòu)建任務(wù)班套;
三、構(gòu)建語法說明:與crontab定時(shí)任務(wù)一樣
1.首先格式為:* * * * *(五個(gè)星)故河;
2.第一個(gè)*表示分鐘吱韭,取值0~59
第二個(gè)*表示小時(shí),取值0~23
第三個(gè)*表示一個(gè)月的第幾天鱼的,取值1~31
第四個(gè)*表示第幾月理盆,取值1~12
第五個(gè)*表示一周中的第幾天,取值0~7凑阶,其中0和7代表的都是周日
【構(gòu)建多個(gè)項(xiàng)目】
【jenkins下載安裝】 http://updates.jenkins-ci.org/download/plugins/deploy/ jenkins郵件設(shè)置
【ssh連接】
- 本地機(jī)器
<pre class="md-fences md-end-block ty-contain-cm" spellcheck="false" lang="s" cid="n66" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); --select-text-bg-color: #36284e; --select-text-font-color: #fff; font-size: 0.9rem; line-height: 1.71429em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; margin-left: 2em; padding-left: 1ch; padding-right: 1ch; width: inherit; color: rgb(31, 9, 9); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">ligang@LAPTOP-5LJTNJJR MINGW64 ~/Desktop
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/ligang/.ssh/id_rsa):
/c/Users/ligang/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/ligang/.ssh/id_rsa.
Your public key has been saved in /c/Users/ligang/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:LI71XID7pnW0nivVU1AIvB9+ybQbr3XZSP6gH4a8Am4 ligang@LAPTOP-5LJTNJJR
The key's randomart image is:
+---[RSA 2048]----+
| ... o. |
| . . o |
| . . . . |
| o .. . o |
| + S o+ =.o |
| + =.o.o=+.o|
| . ..oo oo*=+|
| +Eo.. +.=o|
| .. .+oo.o..|
+----[SHA256]-----+
</pre>