banjollity
banjollity

Reputation: 4540

Can I disable Hudson's automatic scheduled builds all at once?

We have a large Hudson set up with many scheduled builds running all the time. Currently I'm trying to get one build to work properly, but I have to occasionally wait when a scheduled build enters the queue. Is there a way to disable all the scheduled builds so I can concentrate on my troublesome build, without adjusting the "cron" settings of each individual build?

Upvotes: 3

Views: 6295

Answers (6)

Jayan
Jayan

Reputation: 18459

This can be done using jenkins Console. It runs groovy script and do almost anything.

Following script iterates through all projects. Check if it has TimerTrigger.(One can extend this check of other triggers as well)

import hudson.model.Hudson
import hudson.model.Project
import hudson.triggers.TimerTrigger
import hudson.triggers.Trigger
import hudson.triggers.TriggerDescriptor

//All the projects on which we can apply the getBuilders method
def allProjects = Hudson.instance.items.findAll { it instanceof Project }
def projectsToWorkOn = [];
allProjects.each { Project project ->
    Map<TriggerDescriptor, Trigger> triggers =
            project.getTriggers();
    triggers.each { trigger ->

        if (trigger.value instanceof TimerTrigger) {
            projectsToWorkOn.push(project)


        }

    }
}


projectsToWorkOn
        .each { Project project ->

    project.disable();
    project.save()
}

Upvotes: 0

Paul Karlin
Paul Karlin

Reputation: 840

A search for something similar brought me to this question, and I realized there's another benefit of Michael Donohue's answer (and the plugin he contributed).

With "Configuration Slicing," it's easy to disable a subset of your jobs all at once. That's exactly what I needed to temporarily disable 7 of 8 related jobs so I could work on the 8th. Thanks Michael!

Upvotes: 0

Justin Foreman
Justin Foreman

Reputation: 21

Expanding upon Mikezx6r's suggestion, I just came up with a quick method to disable all builds matching a certain string:

[user@server jobs] $ for i in *build_name*; do sed -i s/"disabled>false"/"disabled>true/" $i/config.xml; done

You could also iterate through specific build names in the "for" loop:

[user@server jobs] $ for i in build1 build2 build3; do sed -i s/"disabled>false"/"disabled>true/" $i/config.xml; done

You can test it first to see what it will do by putting an "echo" before sed:

[user@server jobs] $ for i in build1 build2 build3; do echo sed -i s/"disabled>false"/"disabled>true/" $i/config.xml; done

Conversely, you can re-enable all matching jobs by switching around the sed script:

[user@server jobs] $ for i in build1 build2 build3; do sed -i s/"disabled>true"/"disabled>false/" $i/config.xml; done

Upvotes: 2

Tell it to prepare to shut down.


Edit from OP (banjollity)
It's not perfect, but I think this is a reasonable "few mouse clicks solution with a default install" kind of solution, hence the accepted answer.

  1. Queue up a job
  2. Tell Hudson to prepare to shut down. This prevents other jobs being run in the meantime.
  3. Diagnose faults with my job, commit new code that might fix it. (I love my job).
  4. Cancel Hudson shut down.
  5. Goto step 1.

Upvotes: 4

Michael Donohue
Michael Donohue

Reputation: 11876

The 'configuration slicing' plugin I contributed allows you to modify the cron settings of many jobs simultaneously. This should allow you to make the bulk changes you want.

Upvotes: 4

Mikezx6r
Mikezx6r

Reputation: 16905

I don't see a direct way to do it, but you could write something that updates the config.xml for all jobs.

In each job's directory in hudson, there's a config.xml. The <project> has an element called disabled that you could update to true, thereby disabling that build.

Not ideal, but once you have the script to walk a directory and change the value of disabled, you can always use it.

Upvotes: 0

Related Questions