forked from jenkinsci/jenkins-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreloadJobConfig.groovy
37 lines (28 loc) · 959 Bytes
/
reloadJobConfig.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
37
/*** BEGIN META {
"name" : "reload job config",
"comment" : "Reload the job config of a specific job.",
"parameters" : [],
"core": "1.300",
"authors" : [
{ name : "Thomas Froehlich - [email protected]" }
]
} END META**/
import java.io.InputStream;
import java.io.FileInputStream
import java.io.File;
import javax.xml.transform.stream.StreamSource
def hudson = hudson.model.Hudson.instance;
//def env = System.getenv();
//def toBeCopiedJobName = env['JOB_NAME_TO_REPORT_FOR'];
String toBeCopiedJobName = "copiedJob";
//to get a single job
//def job = hudson.model.Hudson.instance.getItem('my-job');
for(job in hudson.model.Hudson.instance.items) {
if (job.name == toBeCopiedJobName) {
def configXMLFile = job.getConfigFile();
def file = configXMLFile.getFile();
InputStream is = new FileInputStream(file);
job.updateByXml(new StreamSource(is));
job.save();
}
}