本文的實現:git
gitlab
pipeline
系統管理 - 系統設置 - gitlab
Enable authentication for '/project' end-point
Connection name
和Gitlab host URL
Gitlab API token
登陸用戶 - User settings - Access Tokens
,建立一個Token記錄Test Connection
測試
Success
多分支流水線
Git
Username with Password
Private
,這個用戶必須是這個項目的成員參考 Jenkinsfile Demogithub
主要配置:web
// 獲取gitlab connection, 填寫咱們以前配置gitlab connection properties([gitLabConnection('gitlab-bigdata')]) // 拉取代碼 checkout scm // 告訴gitlab job狀態 updateGitlabCommitStatus name: 'build', state: 'pending' // 根據不一樣的分支觸發不一樣的步驟 if (env.BRANCH_NAME == 'master' || env.BRANCH_NAME == 'dev' ) { stage("Build Docker Image"){ echo "build docker image" echo "Only dev/master branch can build docker image" } if(env.BRANCH_NAME == 'dev'){ stage("Deploy to test"){ echo "branch dev to deploy to environment test" } stage("Integration test"){ echo "test環境集成測試" } } if(env.BRANCH_NAME == 'master'){ stage("Deploy to prod"){ echo "branch master to deploy to environment prod" } stage("Health check"){ echo "prod檢查" } } }
管理中心 - 設置 - 網絡 - 外發請求(Admin Area - settings - Network - Outbound requests)
Allow requests to the local network from hooks and services
, 保存Gitlab triggerdocker
Settings - Integrations
Push events
和Merge request events
http://JENKINS_URL/project/PROJECT_NAME
When you configure the plugin to trigger your Jenkins job, by following the instructions below depending on job type, it will listen on a dedicated URL for JSON POSTs from GitLab's webhooks. That URL always takes the form http://JENKINS_URL/project/PROJECT_NAME, or http://JENKINS_URL/project/FOLDER/PROJECT_NAME if the project is inside a folder in Jenkins. You should not be using http://JENKINS_URL/job/PROJECT_NAME/build or http://JENKINS_URL/job/gitlab-plugin/buildWithParameters, as this will bypass the plugin completely.
Settings - Integrations
Recent Deliveries
部分,顯示了最近的Trigger狀態200
passed
成功