-
Notifications
You must be signed in to change notification settings - Fork 818
Added executionType parameter to have an ability to run phase jobs SE… #929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,10 @@ class MultiJobStepContext extends StepContext { | |
| 'SUCCESSFUL', 'UNSTABLE', 'COMPLETED', 'FAILURE', 'ALWAYS' | ||
| ] | ||
|
|
||
| private static final List<String> VALID_EXECUTION_TYPES = [ | ||
| 'PARALLEL', 'SEQUENTIALLY' | ||
| ] | ||
|
|
||
| MultiJobStepContext(JobManagement jobManagement, Item item) { | ||
| super(jobManagement, item) | ||
| } | ||
|
|
@@ -19,14 +23,14 @@ class MultiJobStepContext extends StepContext { | |
| * Adds a MultiJob phase. | ||
| */ | ||
| void phase(@DslContext(PhaseContext) Closure phaseContext) { | ||
| phase(null, 'SUCCESSFUL', phaseContext) | ||
| phase(null, 'SUCCESSFUL', 'PARALLEL', phaseContext) | ||
| } | ||
|
|
||
| /** | ||
| * Adds a MultiJob phase. | ||
| */ | ||
| void phase(String phaseName, @DslContext(PhaseContext) Closure phaseContext = null) { | ||
| phase(phaseName, 'SUCCESSFUL', phaseContext) | ||
| phase(phaseName, 'SUCCESSFUL', 'PARALLEL', phaseContext) | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -35,20 +39,29 @@ class MultiJobStepContext extends StepContext { | |
| * {@code continuationCondition} must be one of {@code 'SUCCESSFUL'}, {@code 'UNSTABLE'}, {@code 'COMPLETED'} or | ||
| * {@code 'FAILURE'}. When version 1.16 or later of the MultiJob plugin is installed, {@code continuationCondition} | ||
| * can also be set to {@code 'ALWAYS'}. | ||
| * {@code executionType} must be one of {@code 'PARALLEL'} or {@code 'SEQUENTIALLY'} | ||
| */ | ||
| void phase(String name, String continuationCondition, @DslContext(PhaseContext) Closure phaseClosure) { | ||
| PhaseContext phaseContext = new PhaseContext(jobManagement, item, name, continuationCondition) | ||
| void phase( | ||
| String name, String continuationCondition, String executionType, | ||
| @DslContext(PhaseContext) Closure phaseClosure | ||
| ) { | ||
| PhaseContext phaseContext = new PhaseContext(jobManagement, item, name, continuationCondition, executionType) | ||
| ContextHelper.executeInContext(phaseClosure, phaseContext) | ||
|
|
||
| Preconditions.checkNotNullOrEmpty(phaseContext.phaseName, 'A phase needs a name') | ||
| Preconditions.checkArgument( | ||
| VALID_CONTINUATION_CONDITIONS.contains(phaseContext.continuationCondition), | ||
| "Continuation Condition needs to be one of these values: ${VALID_CONTINUATION_CONDITIONS.join(', ')}" | ||
| ) | ||
| Preconditions.checkArgument( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this check to the |
||
| VALID_EXECUTION_TYPES.contains(phaseContext.executionType), | ||
| "Execution Type needs to be one of these values: ${VALID_EXECUTION_TYPES.join(', ')}" | ||
| ) | ||
|
|
||
| stepNodes << new NodeBuilder().'com.tikal.jenkins.plugins.multijob.MultiJobBuilder' { | ||
| phaseName phaseContext.phaseName | ||
| delegate.continuationCondition(phaseContext.continuationCondition) | ||
| delegate.executionType(phaseContext.executionType) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be wrapped in an if block testing |
||
| phaseJobs { | ||
| phaseContext.jobsInPhase.each { PhaseJobContext jobInPhase -> | ||
| Node phaseJobNode = 'com.tikal.jenkins.plugins.multijob.PhaseJobsConfig' { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,14 +11,19 @@ class PhaseContext extends AbstractContext { | |
|
|
||
| String phaseName | ||
| String continuationCondition | ||
| String executionType | ||
|
|
||
| List<PhaseJobContext> jobsInPhase = [] | ||
|
|
||
| PhaseContext(JobManagement jobManagement, Item item, String phaseName, String continuationCondition) { | ||
| PhaseContext( | ||
| JobManagement jobManagement, Item item, String phaseName, String continuationCondition, | ||
| String executionType | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't add another constructor parameter here. Set the field to the default value. |
||
| ) { | ||
| super(jobManagement) | ||
| this.item = item | ||
| this.phaseName = phaseName | ||
| this.continuationCondition = continuationCondition | ||
| this.executionType = executionType | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -35,6 +40,13 @@ class PhaseContext extends AbstractContext { | |
| this.continuationCondition = continuationCondition | ||
| } | ||
|
|
||
| /** | ||
| * Defines how to run the whole MultiJob phase. | ||
| */ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a |
||
| void executionType(String executionType) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feature need version 1.22 of the MultiJob plugin. Add a |
||
| this.executionType = executionType | ||
| } | ||
|
|
||
| /** | ||
| * Adds a job to the phase. | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,9 +17,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() == 'First' | ||
| continuationCondition[0].value() == 'SUCCESSFUL' | ||
| executionType[0].value() == 'PARALLEL' | ||
| phaseJobs[0].value().empty | ||
| } | ||
|
|
||
|
|
@@ -32,9 +33,10 @@ class MultiJobStepContextSpec extends Specification { | |
| then: | ||
| with(context.stepNodes[1]) { | ||
| name() == 'com.tikal.jenkins.plugins.multijob.MultiJobBuilder' | ||
| children().size() == 3 | ||
| children().size() == 4 | ||
| phaseName[0].value() == 'Second' | ||
| continuationCondition[0].value() == 'SUCCESSFUL' | ||
| executionType[0].value() == 'PARALLEL' | ||
| phaseJobs[0].children().size() == 1 | ||
| with(phaseJobs[0].'com.tikal.jenkins.plugins.multijob.PhaseJobsConfig'[0]) { | ||
| children().size() == 7 | ||
|
|
@@ -60,9 +62,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() == 'Third' | ||
| continuationCondition[0].value() == 'SUCCESSFUL' | ||
| executionType[0].value() == 'PARALLEL' | ||
| phaseJobs[0].children().size() == 3 | ||
| phaseJobs[0].'com.tikal.jenkins.plugins.multijob.PhaseJobsConfig'[0].jobName[0].value() == 'JobA' | ||
| phaseJobs[0].'com.tikal.jenkins.plugins.multijob.PhaseJobsConfig'[1].jobName[0].value() == 'JobB' | ||
|
|
@@ -100,9 +103,10 @@ class MultiJobStepContextSpec extends Specification { | |
|
|
||
| then: | ||
| with(context.stepNodes[0]) { | ||
| children().size() == 3 | ||
| children().size() == 4 | ||
| phaseName[0].value() == 'Fourth' | ||
| continuationCondition[0].value() == 'SUCCESSFUL' | ||
| executionType[0].value() == 'PARALLEL' | ||
| phaseJobs[0].children().size() == 1 | ||
| with(phaseJobs[0].'com.tikal.jenkins.plugins.multijob.PhaseJobsConfig'[0]) { | ||
| children().size() == 8 | ||
|
|
@@ -188,9 +192,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() == 'Second' | ||
| continuationCondition[0].value() == 'SUCCESSFUL' | ||
| executionType[0].value() == 'PARALLEL' | ||
| phaseJobs[0].children().size() == 1 | ||
| with(phaseJobs[0].'com.tikal.jenkins.plugins.multijob.PhaseJobsConfig'[0]) { | ||
| children().size() == 7 | ||
|
|
@@ -220,7 +225,16 @@ class MultiJobStepContextSpec extends Specification { | |
|
|
||
| def 'call phase with unsupported condition'() { | ||
| when: | ||
| context.phase('test', 'FOO') { | ||
| context.phase('test', 'FOO', 'PARALLEL') { | ||
| } | ||
|
|
||
| then: | ||
| thrown(DslScriptException) | ||
| } | ||
|
|
||
| def 'call phase with unsupported execution type'() { | ||
| when: | ||
| context.phase('test', 'SUCCESSFUL', 'BAR') { | ||
| } | ||
|
|
||
| then: | ||
|
|
@@ -232,22 +246,45 @@ class MultiJobStepContextSpec extends Specification { | |
| jobManagement.isMinimumPluginVersionInstalled('jenkins-multijob-plugin', '1.16') >> true | ||
|
|
||
| when: | ||
| context.phase('test', condition) { | ||
| context.phase('test', condition, 'PARALLEL') { | ||
| } | ||
|
|
||
| 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 | ||
| } | ||
|
|
||
| where: | ||
| condition << ['FAILURE', 'ALWAYS'] | ||
| } | ||
|
|
||
| def 'call phase with supported execution type'(String execution) { | ||
| setup: | ||
| jobManagement.isMinimumPluginVersionInstalled('jenkins-multijob-plugin', '1.16') >> true | ||
|
|
||
| when: | ||
| context.phase('test', 'SUCCESSFUL', 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 << ['SEQUENTIALLY'] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do not use a
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is a good option to modify codenarcTest to catch such conditions |
||
| } | ||
|
|
||
| def 'phase works inside conditionalSteps'() { | ||
| when: | ||
| context.conditionalSteps { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will break compatibility as it changes a signature. Leave the signature as it is, just adding a new method to
PhaseContextis sufficient.