Hello,
I have previously used the Jenkins CLI to create a new job from a template. However, (known issue) I am unable to copy Promoted Builds steps as part of this. So I have gone down the path of trying to robocopy the template job to a new job name, and search/replace values within. For some reason Jenkins is not picking up the new job.
Here are the basic steps my script is executing
- Robocopy "\\$JenkinsServer\jobs\$TemplateJob" "\\$JenkinsServer\jobs\$NewBuildJobName" *.* /E /XD .git /XF *.log
- Then using Powershell: replace "##RELEASEVERSION##" flag with my new release version (ie. v17)
- Then using Powershell: replace "<disabled>true</disabled>" with "<disabled>false</disabled>"
- Then write the xml file back out to "\\$JenkinsServer\jobs\$NewBuildJobName\config.xml"
- I then look "\\$JenkinsServer\jobs\$jobname\promotions" and iterate through each promotion level
- I replace "<project>$templateJobName</project>" with "<project>$jobname</project>"
- I then try to use the CLI to reload-configuration (which doesn't work for me, so I do it manually in the UI)
- Doesn't work: java -jar ..\bin\jenkins-cli.jar -s "http://$JenkinsServer/" reload-configuration --username $UserName --password $Password
Once I reload configuration, Jenkins does not see and pick up the new build. I have not been able to find any other config files where build jobs are stored/configuration apart from the jobs folder.
One thing I have noticed through a folder compare with BeyondCompare, is that the new files are Unicode, and not UTF-8, could have be causing my Jenkins issues?
For fun, I have attached my script, if you have any feedback/suggestions I'm all ears.
Assumptions:
A couple functions in the script take a parameter $JenkinsServer, which defaults to localhost, you will need to update as per your environment.
Set these values as per your needs
$ReleaseVersion = "v1.0"
$ProjectToBuild = "MyNewProject"
You have a 'template' job created in the naming format of "template-JobName"
You run Powershell as an Admin
Thank you.
Mike