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:
1. 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)
2. Chef will then be updated to look at the job XML currently on the
Jenkins server
1. If the description includes FROZEN, skip that job and leave it
alone
2. 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
<https://wiki.jenkins-ci.org/display/JENKINS/Groovy+plugin>. Use Groovy
system step -- allows running scripts in Jenkins context (with
Jenkins.instance available).
Java/Groovy API reference:
http://javadoc.jenkins.io/
// getting any job:
def job = Jenkins.instance.getItem("some-job-name");
// BUT`job` here is not just a Job
<http://javadoc.jenkins.io/hudson/model/Job.html>, it is an
AbstractProject
<http://javadoc.jenkins.io/hudson/model/AbstractProject.html>.
// set desc. for current build
build.setDescription(someDescriptionString);
// loop over jobs (possible also in Script Console)
for (item in hudson.model.Hudson.instance.items) {
println("Saving " + item);
item.save();
}
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/08353e5a-6d3e-f01a-1b44-99dd15a3ae4c%40mol.com.pl.
For more options, visit https://groups.google.com/d/optout.