我正在尝试使用job-dsl-plugin编写大量以前手动配置的Jenkins作业的配置脚本。
这些作业中的一种有多个步骤,其中包括几个使用XShell插件的步骤,job-dsl不直接支持此步骤。但是,我应该能够通过使用自定义的“配置”块来解决该问题。
使用http://job-dsl.herokuapp.com/上的“ Job DSL游乐场”,我已经了解到:
job {
name 'my-job'
jdk('JDK-17')
steps {
configure { node ->
node / builders {
'hudson.plugins.xshell.XShellBuilder'(plugin: '[email protected]') {
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: '[email protected]') {
commandLine('run-me-as-the-last-build-step')
executeFromWorkingDir('true')
}
}
}
}
}
如果我仅包括第一个configure块,那么我会在第一步位置得到第一个命令。但是,在存在第二个(最后一个)configure块的情况下,"node / builders"
再次在第一个元素上匹配并覆盖它,因此run-me-as-the-last-step
第一个也是唯一的XShellBuilder也是如此。我寻求的输出将类似于:
<project>
...
<builders>
<hudson.plugins.xshell.XShellBuilder plugin='[email protected]'>
<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='[email protected]'>
<commandLine>run-me-as-the-last-build-step</commandLine>
<executeFromWorkingDir>true</executeFromWorkingDir>
</hudson.plugins.xshell.XShellBuilder>
</builders>
...
</project>
我无法弄清楚Groovy XML / Job-DSL语法是否可以将第二个块插入为“最后一个孩子; Job-DSL或Groovy XMLParser专家可以请我给我一个如何匹配并插入到任意位置的指针。的孩子<builders>
?
(我很感激我可以和一起使用job(type:Maven)
,但实际上我还需要一些其他的东西,而纯粹的maven工作是无法做到的。)谢谢!preBuildSteps
postBuildSteps
您可以使用<<
运算符来追加节点,否则将替换具有相同名称的现有节点。有关详细信息,请参见Job DSL Wiki。
job {
name('foo')
steps {
shell('echo AAA')
}
configure {
it / builders << 'hudson.plugins.xshell.XShellBuilder' {
commandLine('123')
}
}
steps {
shell('echo BBB')
}
configure {
it / builders << 'hudson.plugins.xshell.XShellBuilder' {
commandLine('456')
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句