Updating a Jenkins job with the Groovy Jenkins API -


i'm looking @ using groovy script console create , update jobs on jenkins. using api documented here

http://javadoc.jenkins-ci.org/

i've discovered how create job using createprojectfromxml(string name, inputstream xml)

but method fail if job exists. how can update existing job new xml?

update

based on @ogondza's answer used follow create , update job

import jenkins.* import jenkins.model.* import hudson.* import hudson.model.* import java.io.* import java.nio.charset.standardcharsets import javax.xml.transform.stream.*  config = """......my config.xml......"""  inputstream stream = new bytearrayinputstream(config.getbytes(standardcharsets.utf_8));  job = jenkins.getinstance().getitembyfullname("job_name", abstractitem)  if (job == null) {   println "constructing job"   jenkins.getinstance().createprojectfromxml("job_name", stream); } else {   println "updating job"   job.updatebyxml(new streamsource(stream)); } 

use abstractitem#updatebyxml updating. note can create/update jobs xml using rest api , jenkins cli.


Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -