Over time Jenkins jobs can grow into something “a little confusing”, in other words: like cancer.
The Jenkins developers were thoughtful enough to provide an API to all the data structures, that Jenkins and its jobs operate on, so we are able to export an entire Jenkins job as XML. You certainly do not want to edit a Shell script encapsulated within this XML, or a Windows batch script. You are certainly not the first one to need an export facility for this, and certainly a couple of approaches got developed over time. I am trying to collect them here for you and myself. I actually only found Ken Dreyer’s tool in the beginning – but only after I started developing something myself. NIH applies maybe …
- https://github.com/ktdreyer/jenkins-job-wrecker – Ken Dreyer’s jenkins-job-wrecker – converts Jenkins job XML to JJB YAML
Translate Jenkins XML jobs to YAML. The YAML can then be fed into Jenkins Job Builder.
Have a lot of Jenkins jobs that were crafted by hand over the years? This tool allows you to convert your Jenkins jobs to JJB quickly and accurately.
Initially I was / I am only interested in “project/builders” build steps:
- project/builders/hudson.tasks.BatchFile/command
- project/builders/hudson.tasks.Shell/command
- project/builders/EnvInjectBuilder/info/propertiesContent
- project/builders/EnvInjectBuilder/info/propertiesFilePath
I am extracting the bits and pieces with XPath expressions using XMLStarlet within Shell scripts. Every build step goes into its own file, with names derived from the step’s ordinal number within the Jenkins job, have a look at this example:
- 00–___.properties
- 01–___.propertiesFilePath
- 02–___.sh
- 03–___.bat
These “raw names” push you to think about more reasonable names, that will remind you of their meaning and content from then on.
I called my script “jenkins_config2files.sh“. I am going to upload it to my github account within a couple of days.
Leave a Reply