本文的实现:
成都创新互联公司一直秉承“诚信做人,踏实做事”的原则,不欺瞒客户,是我们最起码的底线! 以服务为基础,以质量求生存,以技术求发展,成交一个客户多一个朋友!为您提供做网站、网站制作、成都网页设计、成都微信小程序、成都网站开发、成都网站制作、成都软件开发、成都app软件开发公司是成都本地专业的网站建设和网站设计公司,等你一起来见证!
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 Demo
主要配置:
// 获取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 trigger
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
成功