how to disable jenkins pipeline job

前端 未结 7 1435
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-06 21:46

I am using pipeline jobs with Jenkins 2.0, but I don\'t see option \'disable job\' as I was used to in older Jenkins versions. Am I missing something? Is it still possible to di

7条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-06 22:35

    If, like me, your Jenkins jobs are automatically created by a DSL workflow, you won't be able to edit the configuration of the top-level Job, that contains all the actual branches, to disable the automatic builds from github hooks. I can't currently find a way to programmatically disable an entire pipeline in the jenkinsfile, outside of using the when triggered by clause on every stage as mentioned in this other SO answer. Besides, that would cause it to run and succeed, which might not be what we want.

    So the solution that felt least-hacky to me was:

    1. Change the name of the Jenkinsfiles on all branches in your repo to something other than Jenkinsfile, so that Jenkins' SCM polling doesn't pick it up. I chose Jenkinsfile.manual. This assumes that the job-auto-creator is set to look for "Jenkinsfile"; adjust as necessary.
    2. The auto-created job should delete itself the next time it scans the repo, whether that's from the github hook, a scheduled scan, or you pressing "scan now".
    3. Manually create a new Multibranch Pipeline job for your repo, setting the Build Configuration to look for Jenkinsfile.manual (or whatever you choose to call it).
    4. Configure whatever branch Behaviors you would normally use, but also add a Property Strategy of All branches get the same properties > Suppress automatic SCM triggering.

    This feels "right" to me, your mileage my vary.

提交回复
热议问题