diff --git a/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/step/MultiJobStepContext.groovy b/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/step/MultiJobStepContext.groovy index 453d32ea5..5f24d1ae4 100644 --- a/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/step/MultiJobStepContext.groovy +++ b/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/step/MultiJobStepContext.groovy @@ -49,6 +49,9 @@ class MultiJobStepContext extends StepContext { stepNodes << new NodeBuilder().'com.tikal.jenkins.plugins.multijob.MultiJobBuilder' { phaseName phaseContext.phaseName delegate.continuationCondition(phaseContext.continuationCondition) + if (jobManagement.isMinimumPluginVersionInstalled('jenkins-multijob-plugin', '1.22')) { + delegate.executionType(phaseContext.executionType) + } phaseJobs { phaseContext.jobsInPhase.each { PhaseJobContext jobInPhase -> Node phaseJobNode = 'com.tikal.jenkins.plugins.multijob.PhaseJobsConfig' { diff --git a/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/step/PhaseContext.groovy b/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/step/PhaseContext.groovy index 587afbc9e..2921b0c5b 100644 --- a/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/step/PhaseContext.groovy +++ b/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/step/PhaseContext.groovy @@ -5,12 +5,19 @@ import javaposse.jobdsl.dsl.ContextHelper import javaposse.jobdsl.dsl.DslContext import javaposse.jobdsl.dsl.Item import javaposse.jobdsl.dsl.JobManagement +import javaposse.jobdsl.dsl.RequiresPlugin +import javaposse.jobdsl.dsl.Preconditions class PhaseContext extends AbstractContext { + private static final List VALID_EXECUTION_TYPES = [ + 'PARALLEL', 'SEQUENTIALLY' + ] + protected final Item item String phaseName String continuationCondition + String executionType = 'PARALLEL' List jobsInPhase = [] @@ -19,6 +26,7 @@ class PhaseContext extends AbstractContext { this.item = item this.phaseName = phaseName this.continuationCondition = continuationCondition + this.executionType = executionType } /** @@ -35,6 +43,19 @@ class PhaseContext extends AbstractContext { this.continuationCondition = continuationCondition } + /** + * Defines how to run the whole MultiJob phase. + * @since 1.52 + */ + @RequiresPlugin(id = 'jenkins-multijob-plugin', minimumVersion = '1.22') + void executionType(String executionType) { + Preconditions.checkArgument( + VALID_EXECUTION_TYPES.contains(executionType), + "Execution Type needs to be one of these values: ${VALID_EXECUTION_TYPES.join(', ')}" + ) + this.executionType = executionType + } + /** * Adds a job to the phase. * diff --git a/job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/helpers/step/MultiJobStepContextSpec.groovy b/job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/helpers/step/MultiJobStepContextSpec.groovy index d98d7ff3a..26363b497 100644 --- a/job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/helpers/step/MultiJobStepContextSpec.groovy +++ b/job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/helpers/step/MultiJobStepContextSpec.groovy @@ -227,9 +227,22 @@ class MultiJobStepContextSpec extends Specification { thrown(DslScriptException) } + def 'call phase with unsupported execution type'() { + setup: + jobManagement.isMinimumPluginVersionInstalled('jenkins-multijob-plugin', '1.22') >> true + + when: + context.phase('test') { + executionType 'FOO' + } + + then: + thrown(DslScriptException) + } + def 'call phase with supported condition'(String condition) { setup: - jobManagement.isMinimumPluginVersionInstalled('jenkins-multijob-plugin', '1.16') >> true + jobManagement.isMinimumPluginVersionInstalled('jenkins-multijob-plugin', '1.22') >> true when: context.phase('test', condition) { @@ -238,9 +251,10 @@ class MultiJobStepContextSpec extends Specification { then: with(context.stepNodes[0]) { name() == 'com.tikal.jenkins.plugins.multijob.MultiJobBuilder' - children().size() == 3 + children().size() == 4 phaseName[0].value() == 'test' continuationCondition[0].value() == condition + executionType[0].value() == 'PARALLEL' phaseJobs[0].value().empty } @@ -248,6 +262,29 @@ class MultiJobStepContextSpec extends Specification { condition << ['FAILURE', 'ALWAYS'] } + def 'call phase with supported execution type'(String execution) { + setup: + jobManagement.isMinimumPluginVersionInstalled('jenkins-multijob-plugin', '1.22') >> true + + when: + context.phase('test') { + executionType execution + } + + then: + with(context.stepNodes[0]) { + name() == 'com.tikal.jenkins.plugins.multijob.MultiJobBuilder' + children().size() == 4 + phaseName[0].value() == 'test' + continuationCondition[0].value() == 'SUCCESSFUL' + executionType[0].value() == execution + phaseJobs[0].value().empty + } + + where: + execution << ['PARALLEL', 'SEQUENTIALLY'] + } + def 'phase works inside conditionalSteps'() { when: context.conditionalSteps {