Jenkins continuous delivery pipeline skip stage based on input

谁说胖子不能爱 提交于 2019-12-04 07:52:09
MaTePe

Can't you do something like this, it will be blue/green whatever you choose from input, and you can then run the deployment depending on it too?

def deployToProduction = true
try{
  input 'Deploy to Production'
}catch(e){
   deployToProduction = false
}

if(deployToProduction){
    println "Deploying to production"
}

There is a better solution I just found. You can access the result of the input like by using the return value. The user has to check the checkbox, to run the optional stage. Otherwise the steps of the stage are skipped. If you skipp the whole stage, the stage will disappear and that "cleans" the stage view history.

stage('do optional stuff?') {
    userInput = input(
        id: 'userInput', message: "Some important question?", parameters: [
        booleanParam(defaultValue: false, description: 'really?', name: 'myValue')
    ])
}

stage('optional: do magic') {
    if (userInput) {
        echo "do magic"
    } else {
        // do what ever you want when skipping this build
        currentBuild.result = "UNSTABLE"
    }
}

How about:

stage('Deploy') {
  when { branch 'master' }
    steps {
      sh '...'
    }
  }
}

the stage will be skipped for commits on other branches and will be green.

Instead of using pipeline as a code Jenkins2 feature, you can setup Jobs with downstream/upstream configuration.

Build -> Unit test -> Deploy to Dev -> Integration tests -> Promote to Prod -> Deploy to Prod

At present it gives more control to choose which version of pipeline you wish to Prod. For greater visibility you can configure Delivery Pipeline using Delivery-Pipeline-Plugin.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!