Morgan Blackthorne (2017-05-08 19:56):
We're using Chef automation around configuring our Jenkins jobs. Basically chef clones a git repo with the job XML files, and then tells Jenkins to use them.
What we want to have is:
- One job to edit other jobs description to say "FROZEN by <user X> at <date:time>" or to remove the FROZEN line (basically a toggle)
- Chef will then be updated to look at the job XML currently on the Jenkins server
- If the description includes FROZEN, skip that job and leave it alone
- If the description does not include FROZEN, update the job from the XML file
I'm not really up to speed on Groovy, so what's the simplest way to approach this? (I already know how to do the XML check for step 2, we can just look at the XML over HTTP.)
This should get you started...
Install Groovy plugin. Use Groovy system step -- allows running scripts in Jenkins context (with Jenkins.instance available).
Java/Groovy API reference:
// getting any job:def job = Jenkins.instance.getItem("some-job-name");// BUT`job` here is not just a Job, it is an AbstractProject.
// set desc. for current buildbuild.setDescription(someDescriptionString);
// loop over jobs (possible also in Script Console)
for (item in hudson.model.Hudson.instance.items) {
println("Saving " + item);
item.save();
}
So I'm a little confused as to setting job to a value, but then referencing build.setDescription afterwards... or should that be job.setDescription?// loop over jobs (possible also in Script Console)
for (item in hudson.model.Hudson.instance.items) {
println("Saving " + item);
item.save();
}
Do I need to save them all, or just the one I modified? Like job.save(); ?