Reputation:
Is there any way to create new Hudson job by one more Hudson job based one previous Jobs?
For example if I need to create new bunch of jobs one by one, Automatically create 4 jobs with similar configuration with different parameter
Basically steps like this
svn cp
command and make it parametrized using scriptsvnbranch
nameOr other word, I need to clone the previous job and give the new branch name where ever $ Branch comes in new job.
Thanks
Upvotes: 17
Views: 31882
Reputation: 31
def jenkins = hudson.model.Hudson.instance
def template = jenkins.getItem("MyTemplate")
def job = jenkins.copy(template,"MyNewJob")
job.save()
I used this now I have to change the parameter values of MyNewJob using Groovy how will I do that?
ex I have a parameter called "Build_BranchName" and the default is //perforce/mybranch I have to change it to //perforce/mynewbranch
Upvotes: 1
Reputation: 525
Kind of already covered in the other answers, but for an easy way to copy the config.xml over:
curl --user USER:PASS -H "Content-Type: text/xml" -s
--data-binary "@config.xml" "http://hudsonserver:8080/createItem?name=newjobname"
Upvotes: 8
Reputation: 31
There seems to be a plugin for jenkins.
https://wiki.jenkins-ci.org/display/JENKINS/Job+DSL+Plugin
I have not tested the plug-in yet. But if the plugin works, it should alleviate some of human errors from straight copying a job and modifying variables/values.
Upvotes: 2
Reputation: 309
You could use groovy system script like this :
def jenkins = hudson.model.Hudson.instance
def template = jenkins.getItem("MyTemplate")
def job = jenkins.copy(template,"MyNewJob")
job.scm = new hudson.scm.SubversionSCM("http://base/branches/mybranche")
job.save()
Upvotes: 8
Reputation: 20184
In case you're willing to use GIT (like I do, mirroring the main SVN repo, onto the Hudson/Jenkins server, and it works great).... ..you could try Stephen Haberman's post-receive-hudson:
This hook creates new jobs for each branch in the Hudson continuous integration tool. Besides creating the job if needed, the user who pushed is added to the job's email list if they were not already there.
In any case, that script can give you new hints on how to remote control Jenkins(Hudson).
Upvotes: 0
Reputation: 16305
You have the option that VonC just gave you (which is probably the safest way but you can also go a different rout by just creating a new directory in {Hudson_Home}\jobs (the directory name will be the job name) and copy a modified config.xml in there. The modification will basically just be the SVN URL. You should check out the xml from the job that you are copying. You need to find out how you change the xml file via script, but this is a secondary problem.
Unfortunately, you have to either restart Hudson, or force a reload of the configuration. (visit the page http://:/reload to reload the config).
Upvotes: 0
Reputation: 1323303
You can try the Hudson Remote API for this kind of task (setting up an Hudson project).
See this tutorial for instance, and remember you can display the help quite easily:
java -jar hudson-cli.jar -s http://your_Hudson_server/ help
So, to copy a job:
java -jar hudson-cli.jar -s http://your_Hudson_server/ copy-job myjob copy-myjob
Upvotes: 12