目录

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

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

转载自:

Jenkins版本:

安装的插件:

//upload-images.jianshu.io/upload_images/6999885-f5d6de4e81f77df7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp

//upload-images.jianshu.io/upload_images/6999885-f33fc8aedb2ca89b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp

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

工作流程:

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

//upload-images.jianshu.io/upload_images/6999885-9d31b6bde0adff03.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp

//upload-images.jianshu.io/upload_images/6999885-b533980dead3e024.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp

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'
    }
}

构建等待输入过程:

//upload-images.jianshu.io/upload_images/6999885-eab304dab320cbf9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/560/format/webp

构建后视图显示:

//upload-images.jianshu.io/upload_images/6999885-1d74baf7ee6d734d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/939/format/webp