Jenkins Job DSL 插件(版本 1.42)允许定义 MultiJobs:
multiJob('MyMultiJob'){
steps{
phase('First')
phaseJob('JobA'){
#job configuration
}
}
}
}
是否可以定义作业并通过单独的步骤将其添加到多作业中,如以下示例所示?
jobA = job('JobA')
multiJob('MyMultiJob'){
steps{
phase('First')
jobA
}
}
}
被迫在多作业定义中定义许多不同的作业似乎很复杂,并且增加了很多复杂性。有解决方法吗?是否可以将阶段作业的定义移动到多作业定义之外的函数?
你可以
这样做
def j= {
parameters {
propertiesFile('my1.properties')
}
}
multiJob('example') {
steps {
phase('First') {
phaseJob('JobZ', j)
}
phase('Second') {
phaseJob('JobA', j)
phaseJob('JobB')
phaseJob('JobC')
}
}
}
您可以使用"j"。参数外的闭包语法是语法糖,方法调用假定闭包实际上是最后一个参数
作业 dsl 操场的输出
<com.tikal.jenkins.plugins.multijob.MultiJobProject plugin='jenkins-multijob-plugin@1.8'>
<actions></actions>
<description></description>
<keepDependencies>false</keepDependencies>
<properties></properties>
<scm class='hudson.scm.NullSCM'></scm>
<canRoam>true</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers class='vector'></triggers>
<concurrentBuild>false</concurrentBuild>
<builders>
<com.tikal.jenkins.plugins.multijob.MultiJobBuilder>
<phaseName>Second</phaseName>
<continuationCondition>SUCCESSFUL</continuationCondition>
<phaseJobs>
<com.tikal.jenkins.plugins.multijob.PhaseJobsConfig>
<jobName>JobZ</jobName>
<currParams>true</currParams>
<exposedSCM>true</exposedSCM>
<disableJob>false</disableJob>
<killPhaseOnJobResultCondition>FAILURE</killPhaseOnJobResultCondition>
<configs>
<hudson.plugins.parameterizedtrigger.FileBuildParameters>
<propertiesFile>my1.properties</propertiesFile>
<failTriggerOnMissing>false</failTriggerOnMissing>
</hudson.plugins.parameterizedtrigger.FileBuildParameters>
</configs>
</com.tikal.jenkins.plugins.multijob.PhaseJobsConfig>
</phaseJobs>
</com.tikal.jenkins.plugins.multijob.MultiJobBuilder>
<com.tikal.jenkins.plugins.multijob.MultiJobBuilder>
<phaseName>Third</phaseName>
<continuationCondition>SUCCESSFUL</continuationCondition>
<phaseJobs>
<com.tikal.jenkins.plugins.multijob.PhaseJobsConfig>
<jobName>JobA</jobName>
<currParams>true</currParams>
<exposedSCM>true</exposedSCM>
<disableJob>false</disableJob>
<killPhaseOnJobResultCondition>FAILURE</killPhaseOnJobResultCondition>
<configs>
<hudson.plugins.parameterizedtrigger.FileBuildParameters>
<propertiesFile>my1.properties</propertiesFile>
<failTriggerOnMissing>false</failTriggerOnMissing>
</hudson.plugins.parameterizedtrigger.FileBuildParameters>
</configs>
</com.tikal.jenkins.plugins.multijob.PhaseJobsConfig>
<com.tikal.jenkins.plugins.multijob.PhaseJobsConfig>
<jobName>JobB</jobName>
<currParams>true</currParams>
<exposedSCM>true</exposedSCM>
<disableJob>false</disableJob>
<killPhaseOnJobResultCondition>FAILURE</killPhaseOnJobResultCondition>
<configs class='java.util.Collections$EmptyList'></configs>
</com.tikal.jenkins.plugins.multijob.PhaseJobsConfig>
<com.tikal.jenkins.plugins.multijob.PhaseJobsConfig>
<jobName>JobC</jobName>
<currParams>true</currParams>
<exposedSCM>true</exposedSCM>
<disableJob>false</disableJob>
<killPhaseOnJobResultCondition>FAILURE</killPhaseOnJobResultCondition>
<configs class='java.util.Collections$EmptyList'></configs>
</com.tikal.jenkins.plugins.multijob.PhaseJobsConfig>
</phaseJobs>
</com.tikal.jenkins.plugins.multijob.MultiJobBuilder>
</builders>
<publishers></publishers>
<buildWrappers></buildWrappers>
</com.tikal.jenkins.plugins.multijob.MultiJobProject>