Jenkins Job DSL plugin(版本1.42)允许定义MultiJobs:
multiJob('MyMultiJob'){
steps{
phase('First')
phaseJob('JobA'){
#job configuration
}
}
}
}
是否可以在单独的步骤中定义作业并将其添加到MultiJob,如下例所示?
jobA = job('JobA')
multiJob('MyMultiJob'){
steps{
phase('First')
jobA
}
}
}
被迫在MultiJob定义中定义许多不同的作业似乎很复杂并且增加了很多复杂性。有变通方法吗?是否可以将阶段作业的定义移动到MultiJob定义之外的函数?
答案 0 :(得分:1)
你可以这样做
def j= {
parameters {
propertiesFile('my1.properties')
}
}
multiJob('example') {
steps {
phase('First') {
phaseJob('JobZ', j)
}
phase('Second') {
phaseJob('JobA', j)
phaseJob('JobB')
phaseJob('JobC')
}
}
}
您可以使用' j'。参数之外的闭包语法是语法糖,方法调用假定闭包实际上是最后一个参数
的输出<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>