Using job-dsl-plugin I am trying to script a large number of Jenkins jobs that were previously manually configured.
One of the advantages of these tasks consists of several steps, including a couple that uses the XShell plugin, this is not directly supported by job-dsl. However, I could get around this using the special "configure" block.
Using the "Job DSL playground" at http://job-dsl.herokuapp.com/ So far I have received:
job { name 'my-job' jdk('JDK-17') steps { configure { node -> node / builders { 'hudson.plugins.xshell.XShellBuilder'(plugin: ' xshell@0.9 ') { commandLine('run-me-as-the-first-build-step') executeFromWorkingDir('true') } } } maven { mavenInstallation('Default') goals('clean') goals('verify') property('prop1', 'value1') property('user.timezone', 'UTC') mavenOpts('--batch-mode') } maven { mavenInstallation('Default') goals('deploy') property('prop2', 'value2') property('user.timezone', 'UTC') mavenOpts('--batch-mode') } shell('shell-task') configure { node -> node / builders { 'hudson.plugins.xshell.XShellBuilder'(plugin: ' xshell@0.9 ') { commandLine('run-me-as-the-last-build-step') executeFromWorkingDir('true') } } } } }
If I just turn on only the first configuration block, I will get the first command in the position of the first step. But with the second (last) configuration block, "node / builders" again matches the first element and overwrites it, so run-me-as-the-last-step is the first and only XShellBuilder. The result I'm looking for will look something like this:
<project> ... <builders> <hudson.plugins.xshell.XShellBuilder plugin=' xshell@0.9 '> <commandLine>run-me-as-the-first-build-step</commandLine> <executeFromWorkingDir>true</executeFromWorkingDir> </hudson.plugins.xshell.XShellBuilder> <hudson.tasks.Maven> <targets>clean verify</targets> <properties>prop1=value1 user.timezone=UTC</properties> <mavenName>Default</mavenName> <jvmOptions>--batch-mode</jvmOptions> <usePrivateRepository>false</usePrivateRepository> </hudson.tasks.Maven> <hudson.tasks.Maven> <targets>deploy</targets> <properties>prop2=value2 user.timezone=UTC</properties> <mavenName>Default</mavenName> <jvmOptions>--batch-mode</jvmOptions> <usePrivateRepository>false</usePrivateRepository> </hudson.tasks.Maven> <hudson.tasks.Shell> <command>shell-task</command> </hudson.tasks.Shell> <hudson.plugins.xshell.XShellBuilder plugin=' xshell@0.9 '> <commandLine>run-me-as-the-last-build-step</commandLine> <executeFromWorkingDir>true</executeFromWorkingDir> </hudson.plugins.xshell.XShellBuilder> </builders> ... </project>
I can’t understand the Groovy XML / Job-DSL syntax to insert this second block as the “last child”, can the Job-DSL XML analysis expert or Groovy give me a pointer on how to map and paste into arbitrary position in child elements <builders> ?
(I appreciate that I could use job(type:Maven) with preBuildSteps and postBuildSteps , but actually I need something else that excludes the pure maven job). Thank you
source share