Jenkins xml configuration for Groovy based on Jenkins Job DSL

Can someone give me a useful link where I can find information on transforming a complex xml configuration for Jenkins jobs?

Here is an example of Jenkins work:

<project> <actions/> <description>Description</description> <logRotator class="hudson.tasks.LogRotator"> <!-- ...--> </logRotator> <keepDependencies>false</keepDependencies> <properties> <hudson.model.ParametersDefinitionProperty/><!-- ...--> </properties> <scm class="org.jenkinsci.plugins.multiplescms.MultiSCM" plugin=" multiple-scms@0.5 "> <scms> <hudson.plugins.git.GitSCM plugin=" git@2.4.0 "/><!-- ...--> <hudson.plugins.git.GitSCM plugin=" git@2.4.0 "/><!-- ...--> </scms> </scm> <canRoam>true</canRoam> <disabled>false</disabled> <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> <jdk>Default</jdk> <triggers> <hudson.triggers.TimerTrigger/><!-- ...--> </triggers> <concurrentBuild>false</concurrentBuild> <customWorkspace>$HUDSON_WD/$REVISION/checkout</customWorkspace> <builders/> <publishers> <hudson.plugins.globalenvvar.GlobalEnvironmentVariablePublisher plugin=" globalenvvar@1.0 "/><!-- ...--> <hudson.plugins.parameterizedtrigger.BuildTrigger plugin=" parameterized-trigger@2.28 "/><!-- ...--> <hudson.plugins.templateproject.ProxyPublisher plugin=" template-project@1.5 "/><!-- ...--> </publishers> <buildWrappers> <hudson.plugins.timestamper.TimestamperBuildWrapper plugin=" timestamper@1.7.2 "/> </buildWrappers> </project> 
+5
source share
1 answer

In my experience, this is a completely manual rewriting process. Reference material is located at https://jenkinsci.imtqy.com/job-dsl-plugin/# .

Many elements in xml defaults, so most xml can be skipped. You only need to convert the xml element by element if the DSL does not directly support the plugin or the plugin function that you configured.

The conversion process is as follows:

  • Go through each configured property (via the Jenkins GUI), for example. Discard old builds.
  • Determine if DSL has built-in support for this item. If so, rewrite it in DSL. For example, logRotator provides the "Undo old builds" functionality.
  • If DSL is not directly supported, you need to manually use configure to output xml. This is quite complicated and can be avoided, if at all possible.

If you don’t know which plugin provides the job item, you can often see the plugin name in the help text for that item (click the small question mark icon). Otherwise, the xml element often contains the name of the plugin.

It is also useful to know that job items are split equally in DSL, as they are on the Jenkins Configure screen. Therefore, if it is a trigger, you can find it in DSL under triggers .

A simple example (I know yours is much more complicated):

 freeStyleJob("Arthur Example") { description('Description') logRotator(30) } 
+9
source

Source: https://habr.com/ru/post/1238873/


All Articles