Jenkins 流水線(Pipeline)
說明:在任務項目構建的過程中通過Pipeline來呈現每個構建階段的細節信息。
配置 Pipeline
1、創建流水線任務
2、根據場景添加需要等項目、注:我這里根據上一節的內容一次添加,以測試為主。
....略(自定義)
3、使用Pipeline流水線Shell、保存。
使用Hello World模板
4、Pipeline-test 任務 --> Build with Parameters --> Build 構建
Pipeline-test 任務 --> Console Output 查看日志
Pipeline-test 任務 --> Full Stage View 點擊查看視圖
通過git來存放jenkins Pipeline文件
1、git服務器操作:通過git創建jenkinsfile倉庫
# 切換git用戶 su - git # 創建jenkinsfile倉庫 mkdir jenkinsfile cd jenkinsfile # 初始話git倉庫 git --bare init
2、客戶端操作:下載git倉庫提交pipeline腳本
# 1、下載倉庫 git clone git@118.31.225.36:/home/git/jenkinsfile cd jenkinsfile/
# 2、創建文件、腳本主要測試4個動作 # (1)、拉取庫 # (2)、maven 打包 # (3)、發布服務 # (4)、自動化測試
vi Jenkinsfile

node { //def mvnHome stage('checkout') { // for display purposes checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'git@118.31.225.36:/home/git/repos/app.git']]]) } stage('maven Build') { echo 'maven build...' } stage('deploy') { echo 'deploy...' } stage('test') { echo 'test...' } }
# 3、提交文件 git add . git commit -m "jenkinsfile" git push origin master
3、jenkins 添加 git庫中的pipeline文件、保存。
- Definition:選擇SCM以git庫文件下載形式
- SCM:選擇git
- Repositories:添加Git倉庫
- Branches to build:使用master分支
- Script Path:庫中指定pipeline腳本路徑
4、查看 Stage View
5、查看日志,直接點擊綠色部分
Pipeline Syntax 生成git流水線腳本
1、Git使用:Checkout
- Sample Step:選擇方法
- Repositories:輸入git倉庫
- Generate Pipeline Script:生存Pipeline腳本
pipeline腳本:
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'git@118.31.225.36:/home/git/repos/app.git']]])
Pipeline Syntax 生成echo流水線腳本
1、使用 echo
- Sample Step:選擇方法
- Message:輸入內容
- Generate Pipeline Script:生存Pipeline腳本
pipeline腳本:
echo 'test'
其他
通過Slave節點構建 pipline語法格式
說明:node(‘指定Slave標簽或名稱’)

node ('web') { //def mvnHome stage('checkout') { // for display purposes checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'git@118.31.225.36:/home/git/repos/app.git']]]) } stage('maven Build') { echo 'maven build...' } stage('deploy') { echo 'deploy...' } stage('test') { echo 'test...' }