forked from cloudbees/jenkins-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schedule-templatized-jobs.groovy
36 lines (33 loc) · 1.25 KB
/
schedule-templatized-jobs.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*** BEGIN META {
"name" : "Schedule Templatized Jobs",
"comment" : "Schedule all Jobs based on a specific template with few parameters such as quiet period, throttleLimit and sleep interval.",
"parameters" : [ ],
"core": "1.609",
"authors" : [
{ name : "Allan Burdajewicz" }
]
} END META**/
import com.cloudbees.hudson.plugins.modeling.impl.jobTemplate.JobPropertyImpl
import hudson.model.Job
import jenkins.model.Jenkins
/**
* This example schedule all job templatized via the Template `templateName`. If more than 5 jobs are to be scheduled,
* the script schedules 5 jobs every 2.1 seconds. Each Job is scheduled with a quiet period of 2 seconds.
*/
//Sleep interval in milliseconds
int sleepInterval = 2100;
//Number of jobs to schedules every sleep interval
int throttleLimit = 5;
//Quiet period in seconds
int quietPeriod = 2;
Jenkins.instance.getAllItems(Job.class)
.findAll { item -> item.getProperty(JobPropertyImpl.class)}
.findAll { item -> item.getProperty(JobPropertyImpl.class).getModel().name == "templateName"}
.each {
while(Jenkins.instance.getQueue().getItems().size() > throttleLimit) {
print "."
sleep(sleepInterval);
}
print "\nScheduling ${it.name}";
it.scheduleBuild2(quietPeriod);
}