簡介java
多分支的管道是在jenkins2.x中新增的功能 。node
多分支管道容許你針對分佈式的控制器的每一個分支建立一個管道。 下圖是對它的一個描述。使用jenkinsfile去建立多分支的管道,jenkinsfile能夠存放在代碼倉庫中。 Jenkinsfile只是定義CI管道的一個腳本。git
另外,多分支管道的設計初衷就是當Git倉庫中的代碼改變時,去自動觸發構建。下圖是對它的一個描述。github
(1)在【全局工具配置】中Maven工具已經配置好。
(2)安裝了【Pipeline Maven Integration Plugin】
(3)Java工具也須要安裝好,因爲咱們構建是在jenkins master上執行,因此能夠跳過此步(由於咱們在安裝Jenkins時,已經安裝好Java)
(4)安裝Gitlab插件,本實驗使用gitlab作爲代碼管理web
添加gitlab憑據到jenkins中api
添加全局憑據安全
gitlab建立我的訪問令牌(personal access token)服務器
jenkins添加gitlabmaven
添加後,test測試報錯分佈式
點擊高級模式,選擇API-levle爲v3
升級git版本
[root@node1 ~]# wget https://github.com/git/git/archive/v2.2.1.tar.gz
[root@node1 ~]# tar -xf v2.2.1.tar.gz
[root@node1 ~]# cd git-2.2.1/
[root@node1 git-2.2.1]# yum install perl-ExtUtils-MakeMaker
[root@node1 git-2.2.1]# yum install zlib-devel
[root@node1 git-2.2.1]# make configure
GIT_VERSION = 2.2.1
GEN configure
[root@node1 git-2.2.1]# ./configure --prefix=/usr/local/git --with-iconv=/usr/local/libiconv
[root@node1 git-2.2.1]# make
[root@node1 git-2.2.1]# make install
[root@node1 git-2.2.1]# ln -s /usr/local/git/bin/git /usr/bin/
[root@node1 git-2.2.1]# git --version
git version 2.2.1
問題依然出現,最後排查的過程當中發現,複製的不是真正的token,這是坑爹的地方
安裝成功
node ('master') { checkout scm stage('Build') { withMaven(maven: 'M3') { if (isUnix()) { sh 'mvn -Dmaven.test.failure.ignore clean install package' } else { bat 'mvn -Dmaven.test.failure.ignore clean install package' } } } stage('Results') { junit '**/target/surefire-reports/TEST-*.xml' archive 'target/*.jar' } } installinstall
提交,開始建立多分枝流水線
出現錯誤:是由於 /usr/libexec/git-core/ 路徑沒在 PATH 環境變量中。
Started by user darren ning [Sat Oct 26 14:12:57 EDT 2019] Starting branch indexing... > git --version # timeout=10 using GIT_ASKPASS to set credentials > git ls-remote http://192.168.132.132/root/simple-maven-project-with-tests.git # timeout=10 ERROR: [Sat Oct 26 14:12:57 EDT 2019] Could not update folder level actions from source 9d2e73ea-7ee8-4128-a8b2-0d7f20e75599 hudson.plugins.git.GitException: Command "git ls-remote http://192.168.132.132/root/simple-maven-project-with-tests.git" returned status code 128: stdout: stderr: fatal: Unable to find remote helper for 'http' at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2042) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1761) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1666) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1657) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.getRemoteReferences(CliGitAPIImpl.java:2877) at jenkins.plugins.git.AbstractGitSCMSource.retrieveActions(AbstractGitSCMSource.java:1139) at jenkins.scm.api.SCMSource.fetchActions(SCMSource.java:848) at jenkins.branch.MultiBranchProject.computeChildren(MultiBranchProject.java:592) at com.cloudbees.hudson.plugins.folder.computed.ComputedFolder.updateChildren(ComputedFolder.java:277) at com.cloudbees.hudson.plugins.folder.computed.FolderComputation.run(FolderComputation.java:164) at jenkins.branch.MultiBranchProject$BranchIndexing.run(MultiBranchProject.java:1026) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:429) [Sat Oct 26 14:12:57 EDT 2019] Finished branch indexing. Indexing took 19 ms FATAL: Failed to recompute children of simple-maven-project-with-tests hudson.plugins.git.GitException: Command "git ls-remote http://192.168.132.132/root/simple-maven-project-with-tests.git" returned status code 128: stdout: stderr: fatal: Unable to find remote helper for 'http' at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2042) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1761) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1666) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1657) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.getRemoteReferences(CliGitAPIImpl.java:2877) at jenkins.plugins.git.AbstractGitSCMSource.retrieveActions(AbstractGitSCMSource.java:1139) at jenkins.scm.api.SCMSource.fetchActions(SCMSource.java:848) at jenkins.branch.MultiBranchProject.computeChildren(MultiBranchProject.java:592) at com.cloudbees.hudson.plugins.folder.computed.ComputedFolder.updateChildren(ComputedFolder.java:277) at com.cloudbees.hudson.plugins.folder.computed.FolderComputation.run(FolderComputation.java:164) at jenkins.branch.MultiBranchProject$BranchIndexing.run(MultiBranchProject.java:1026) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:429) Finished: FAILURE
添加xport PATH=/usr/libexec/git-core:$PATH到/etc/profile裏
在此執行
Started by user darren ning [Sat Oct 26 14:30:07 EDT 2019] Starting branch indexing... > git --version # timeout=10 using GIT_ASKPASS to set credentials > git ls-remote http://192.168.132.132/root/simple-maven-project-with-tests.git # timeout=10 Creating git repository in /root/.jenkins/caches/git-308bd15be61318b6e1166e23433fdd72 > git init /root/.jenkins/caches/git-308bd15be61318b6e1166e23433fdd72 # timeout=10 Setting origin to http://192.168.132.132/root/simple-maven-project-with-tests.git > git config remote.origin.url http://192.168.132.132/root/simple-maven-project-with-tests.git # timeout=10 Fetching & pruning origin... Listing remote references... > git config --get remote.origin.url # timeout=10 > git --version # timeout=10 using GIT_ASKPASS to set credentials > git ls-remote -h http://192.168.132.132/root/simple-maven-project-with-tests.git # timeout=10 Fetching upstream changes from origin > git config --get remote.origin.url # timeout=10 using GIT_ASKPASS to set credentials > git fetch --tags --progress origin +refs/heads/*:refs/remotes/origin/* --prune Checking branches... Checking branch master ‘Jenkinsfile’ found Met criteria Scheduled build for branch: master Checking branch feature ‘Jenkinsfile’ found Met criteria Scheduled build for branch: feature Processed 2 branches [Sat Oct 26 14:30:08 EDT 2019] Finished branch indexing. Indexing took 1 sec Finished: SUCCESS
已經完成