Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Jenkins Job from Another Job

Tags:

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
like image 294
Matt N Avatar asked Dec 28 '11 21:12

Matt N


People also ask

How do I temporarily disable Jenkins?

In order to prevent Jenkins from executing any jobs, you need to put it in "quiet down" mode when it starts up. There are two ways you can do this. You can install and use the Quiet Start plugin. This will give you a UI option to restart Jenkins and have it be in "quiet down" mode when it starts up.

How do I stop a Jenkins job?

Pipeline jobs can be stopped by sending an HTTP POST request to URL endpoints of a build. BUILD ID URL/stop - aborts a Pipeline. BUILD ID URL/term - forcibly terminates a build (should only be used if stop does not work). BUILD ID URL/kill - hard kill a pipeline.

What is disable project in Jenkins?

disabled(boolean shouldDisable = true) Disables the job, so that no new builds will be executed until the project is re-enabled.


2 Answers

It's possible to do this using the Job DSL Plugin, without specifying credentials.

The DSL script to use would be:

job("jobname"){
    using("jobname")
    disabled(true)
}
  1. This is for Freestyle jobs. If you need to disable, for example, a Pipeline Job, use pipelineJob instead of job.
  2. Usually, "jobname" needs to include folders, using the Jenkins root as reference.
  3. To reenable a job, use disabled(false).
like image 198
Javier Garcés Avatar answered Sep 29 '22 11:09

Javier Garcés


Recent version of Jenkins (2 and over) change the method name.
Just replace disable() with setDisabled(boolean)

Found that this worked for me:
Jenkins.instance.getItem("jobname").setDisabled(false)

like image 35
Maimon Avatar answered Sep 29 '22 10:09

Maimon