Stop builds for a period of the day

45 views
Skip to first unread message

John Carbasse

unread,
Mar 2, 2015, 5:52:29 AM3/2/15
to jenkins...@googlegroups.com
Hello,
Is it possible, in Jenkins or by a plugin, to forbid builds for a period (12h-14h for exemple) ?
Ideally, I look for a global parameter, I have too many jobs for set it for each.

Thanks for your time

Stephen Connolly

unread,
Mar 2, 2015, 9:26:09 AM3/2/15
to jenkins...@googlegroups.com
just turn on "prepare for shutdown" and turn it off again when you're done

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/f3ac9d12-93e0-4d1d-a4f2-385ebbb39868%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Scott Evans

unread,
Mar 2, 2015, 9:46:37 AM3/2/15
to jenkins...@googlegroups.com
Another option if you want to do it programmatically could be to use an API call via url hit to take machines offline, then put them back online.  The general format of the call should be available pretty easily with a web search, but we use something like this in a curl call when wanting to take machines offline for regular scripted maintenance:

https://<user>:<apikey>@<jenkinshost>/computer/<nodename>/toggleOffline?offlineMessage=Offline_For_Maintenance_Script

And then run it again to put the machine back online.  The only negative is that this call toggles the online/offline state, and I am not aware of a call which can be made to explicitly put a node online, or offline; just the toggle of current state.  This will take the machine offline gracefully, where any running builds will complete, but no new builds will be started.

This call could be done via a separate job on the Jenkins server itself (running on a node that doesn't get taken offline), or via any sort of external scheduling mechanism you'd like that has the ability to do a http request.

Scott

Matthew...@diamond.ac.uk

unread,
Mar 2, 2015, 10:23:04 AM3/2/15
to jenkins...@googlegroups.com

Just be aware that jobs that are scheduled to run during that period are still scheduled, and you see them waiting in the Build Queue.

 

Also, be careful if you have slaves configured “take this slave on-line when in demand, and off-line when idle”. If you have a job that Is tied to a particular slave, then when the job is put in the build queue, the slave will be taken online even if Jenkins is in “prepare for shutdown” state.

 


For more options, visit https://groups.google.com/d/optout.

 

-- 

This e-mail and any attachments may contain confidential, copyright and or privileged material, and are for the use of the intended addressee only. If you are not the intended addressee or an authorised recipient of the addressee please notify us of receipt by returning the e-mail and do not use, copy, retain, distribute or disclose the information in or attached to the e-mail.
Any opinions expressed within this e-mail are those of the individual and not necessarily of Diamond Light Source Ltd.
Diamond Light Source Ltd. cannot guarantee that this e-mail or any attachments are free from viruses and we cannot accept liability for any damage which you may sustain as a result of software viruses which may be transmitted in or with the message.
Diamond Light Source Limited (company no. 4375679). Registered in England and Wales with its registered office at Diamond House, Harwell Science and Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom
 

Christopher Orr

unread,
Mar 2, 2015, 3:05:05 PM3/2/15
to jenkins...@googlegroups.com
Sounds like the Slave Squatter plugin could help:
https://wiki.jenkins-ci.org/display/JENKINS/Slave+Squatter+Plugin
> --
> You received this message because you are subscribed to the Google
> Groups "Jenkins Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to jenkinsci-use...@googlegroups.com
> <mailto:jenkinsci-use...@googlegroups.com>.
> <https://groups.google.com/d/msgid/jenkinsci-users/f3ac9d12-93e0-4d1d-a4f2-385ebbb39868%40googlegroups.com?utm_medium=email&utm_source=footer>.

John Carbasse

unread,
Mar 3, 2015, 3:58:12 AM3/3/15
to jenkins...@googlegroups.com
Hi,
Sounds like Slave Squatter plugin is a good solution for me, I'll give it a try and if it's not what I want, I'll try with the API.
Thank you all for your help !

Cristian Măgherușan-Stanciu

unread,
Mar 3, 2015, 6:07:49 AM3/3/15
to jenkins...@googlegroups.com
We did it with a bit of Groovy, and we're using it for only enabling our automated continuous deployments during business hours:

import jenkins.model.*
import hudson.model.*


def jobPattern = "_Deploy_PR*"


def c= new GregorianCalendar()
def hour = c.get(Calendar.HOUR_OF_DAY)


if ((hour >= 10) && (hour < 16)) {
 
def matchedJobs = Jenkins.instance.items.findAll { job ->
        job
.name =~ /$jobPattern/
   
}
    matchedJobs
.each { job ->
       
            println
"Enabling  matching job ${job.name}"
    job
.enable()
         
}      
   
}
 
else {
 
def matchedJobs = Jenkins.instance.items.findAll { job ->
        job
.name =~ /$jobPattern/
       
}
    matchedJobs
.each { job ->      
            println
"Disabling matching job ${job.name}"
            job
.disable()
         
   
}
       
   
}



Cristian Măgherușan-Stanciu

unread,
Mar 3, 2015, 6:19:18 AM3/3/15
to jenkins...@googlegroups.com
After pasting it, I noticed that the Groovy script could use a bit of refactoring to make it a bit cleaner:

import jenkins.model.*
import hudson.model.*

def c = new GregorianCalendar()
def hour = c.get(Calendar.HOUR_OF_DAY)

def jobPattern = "_Deploy_PR*"

def matchedJobs = Jenkins.instance.items.findAll { job -> job.name =~ /$jobPattern/ }

matchedJobs
.each { job ->
 
if ((hour >= 10) && (hour < 16)) {
    println
"Enabling  matching job ${job.name}"
    job
.enable()
 
} else {
Reply all
Reply to author
Forward
0 new messages