Jenkins – Disable Jenkins Job from Another Job

Jenkins

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 same Jenkins instance to do some other stuff like install new versions of our product automatically (which is needed for some of the automated tests). When we are running some of the "extra" jobs, we want to disable the "standard" jobs temporarily (and then automatically enable them later).

Ideally there would be some extra build step on a job to say "Disable XYZ job". Or if there is a way through ANT or something to tell Jenkins to disable a job, that would work too.

Update:
It looks like there are a couple plugins that will prevent two jobs from running at the same time, but I really need to:

  1. Run job A which disables job 1
  2. Do some stuff outside of Jenkins based on output of job A
  3. Run job B which which enable job 1 again

Best Answer

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.