Disable Jenkins Job from Another Job

后端 未结 7 1310
夕颜
夕颜 2020-12-16 01:20

Is there a way in Jenkins (Hudson) to disable a job from another job?

Basically we have a build environment that does the standard building/testing. We also use the

7条回答
  •  醉梦人生
    2020-12-16 01:52

    You can execute a Groovy script as a pre build step. I have done this a couple of times at my company. You have to install the Groovy plugin. Then you can add a pre build step "Execute system groovy script" and there you can execute something like that:

    Jenkins.instance.getItem("jobname").disable()
    

    For enabling of jobs after the build add a post build step and execute

    Jenkins.instance.getItem("jobname").enable()
    

    If you want a job, that only enables or disables other build jobs, then you don't choose pre or post build steps, but a normal build step with a system Groovy script.

    You can do many more thinks with Groovy scripts. It is worth to read more about it.

提交回复
热议问题