Have a lot of Jenkins jobs that were crafted by hand over the years? This tool could help you to convert your Jenkins jobs to JJB YAML.
Follow https://github.com/ktdreyer/jenkins-job-wrecker
for JOB in `curl http://$JENKINS_ADDRESS/view/EAP7/view/PrettyPrint/api/json?pretty=true 2> /dev/null| grep name | grep pretty-print | cut -d: -f2 | cut -d\" -f2`; do
echo "$JOB"
curl -s -k --negotiate -u aaa:a https://$JENKINS_ADDRESS/job/$JOB/config.xml > $JOB.xml
done
jjwrecker -f pretty-print-smoke-rhel.xml -n pretty-print-smoke-rhel -o jjb
cat jjb/pretty-print-smoke-rhel.yml
for i in `ls pretty-print-*`; do echo $i; jjwrecker -f $i -n `echo $i | sed "s/.xml//g"` -o jjb; done
Result: 3x fail, related to this xml snipet which can't be processed / transformed:
<org.jenkinsci.plugins.proccleaner.PreBuildCleanup plugin="[email protected]">
<cleaner class="org.jenkinsci.plugins.proccleaner.PsCleaner">
<killerType>org.jenkinsci.plugins.proccleaner.PsAllKiller</killerType>
<killer class="org.jenkinsci.plugins.proccleaner.PsAllKiller" reference="../../../../publishers/org.jenkinsci.plugins.proccleaner.PostBuildCleanup/cleaner/killer"/>
<switchedOff>false</switchedOff>
</cleaner>
</org.jenkinsci.plugins.proccleaner.PreBuildCleanup>
Experiment to convert back jobs generated by JJB (see my Jenkins Job Builder experiments ) into YAML files.
JJW_USERNAME=admin JJW_PASSWORD=xxxx jjwrecker -s http://localhost:8080/
YAML files will be stored in out
directory.
JJW:
- Transforms freestyle (partially)
- Cannot tranform Maven jobs, raw xml present in yaml file
- Cannot tranform Pipeline jobs, raw xml present in yaml file
- Tranformation of JJB based jobs is not 100%
- Tranformation of JJB based jobs didn't happen on ArtifactArchiver, JUnitResultArchiver, BuildTimeoutWrapper, xml snippets in YAML file
- Custom plugins are pain for JJW
- PreBuildCleanup, PostBuildCleanup are causing JJW to fail
- JJW is good tool for simple freestyle jobs without many pre-build and post-build actions
- JJW is worth trying, at least it helps with YAML conversion
Examples of problematic snipets:
properties:
- raw:
xml: |
<com.synopsys.arc.jenkins.plugins.ownership.jobs.JobOwnerJobProperty plugin="[email protected]">
<ownership>
<ownershipEnabled>true</ownershipEnabled>
<primaryOwnerId>[email protected]</primaryOwnerId>
<coownersIds class="sorted-set" />
</ownership>
</com.synopsys.arc.jenkins.plugins.ownership.jobs.JobOwnerJobProperty>
- raw:
xml: |
<com.chikli.hudson.plugin.naginator.NaginatorOptOutProperty plugin="[email protected]">
<optOut>false</optOut>
</com.chikli.hudson.plugin.naginator.NaginatorOptOutProperty>
- raw:
xml: |
<com.sonyericsson.rebuild.RebuildSettings plugin="[email protected]">
<autoRebuild>false</autoRebuild>
<rebuildDisabled>false</rebuildDisabled>
</com.sonyericsson.rebuild.RebuildSettings>
publishers:
- raw:
xml: |
<hudson.plugins.descriptionsetter.DescriptionSetterPublisher plugin="[email protected]">
<regexp />
<regexpForFailed />
<description>${EAP_VERSION}</description>
<descriptionForFailed>${EAP_VERSION}</descriptionForFailed>
<setForMatrix>false</setForMatrix>
</hudson.plugins.descriptionsetter.DescriptionSetterPublisher>