Jenkins: How to skip a specific stage in a multibranch pipeline?

岁酱吖の 提交于 2019-12-11 18:15:03

问题


We have "stage (build)" on all our branches. Temporarily how can we skip this stage to run on all our branches in multibranch pipeline. I know one solution is use when condition on stage and ask all developers to pull that branch into their branch. But thats lot of work and coordination. Instead I am looking for a global configuration where we can simply skip the stage by name on any branch.


回答1:


It sounds like you keep the Jenkinsfile alongside the code, but want to change how the Jenkinsfile runs from an administrative point of view.

You could store this stage in a separate (version control flavor of preference) repository. Before you execute the stage, load in the repository then load in the script file and within the stage execute a method defined in that file.

Alternatively, add a parameter to the build job (this assumes you aren't setting parameters via options in the Jenkinsfile) that is a boolean to use or skip the stage and you can modify the project configuration when you want to turn it on or off




回答2:


What about this approach ?

  stage('build') { 

    if(buildFlag=="disable"){
      //jump to next stage
      return;
    }
    //do something
  } 

buildFlag could be

  • a simple var in the same pipeline
  • a global var configured in jenkins. You could set disabled temporarily to skip build stage and change to enabled to restore to normalcy

Also you could set the status to failure, instead of return :

currentBuild.result = 'FAILURE'

Or throw an exception and exit the entire job or pipeline.



来源:https://stackoverflow.com/questions/51405979/jenkins-how-to-skip-a-specific-stage-in-a-multibranch-pipeline

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