Jenkins Pipeline流水线发布 编译打包-发布测试-发布生产 一个任务搞定

Jenkins版本:Jenkins ver. 2.165

安装的插件:

Pipeline
SSH Pipeline Steps

image.png

image.png

有些插件没有用到,由于是安装jenkins时默认安装的。

工作流程:

  1. 获取代码、编译打包
  2. 等待用户输入确认是否发布测试环境(或者预生产环境)
  3. 等待用户输入确认是否发布发布生产环境第一台主机
  4. 等待用户输入确认是否发布发布生产环境第二台主机
image.png
image.png

Pipeline script:

node {
    stage('build'){
        checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '44222250-cfd7-45f4-558e-209f410fddc9', url: 'http://jenkins@git.gitlab.com/aaa/aaa.git']]])
        sh label: '', script: 'mvn clean package install'    
    }
    stage('push_uat') { 
        timeout(time: 7, unit: 'DAYS') {
            input message: '是否发布到预生产?',ok: 'Yes'
        }
        sh label: '', script: '/shell/deploy_v2.sh uat'
    }
    stage('push_online1') { 
        timeout(time: 7, unit: 'DAYS') {
            input message: '是否发布到生产online1?',ok: 'Yes'
        }
        sh label: '', script: '/shell/deploy_v2.sh online1'
    }
    stage('push_online2') { 
        timeout(time: 7, unit: 'DAYS') {
            input message: '是否发布到生产online2?',ok: 'Yes'
        }
        sh label: '', script: '/shell/deploy_v2.sh online2'
    }
}

构建等待输入过程:

image.png

构建后视图显示:

image.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容