-
Notifications
You must be signed in to change notification settings - Fork 830
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
Added executionType parameter to have an ability to run phase jobs SE… #929
Changes from 2 commits
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 |
---|---|---|
|
@@ -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<String> VALID_EXECUTION_TYPES = [ | ||
'PARALLEL', 'SEQUENTIALLY' | ||
] | ||
|
||
protected final Item item | ||
|
||
String phaseName | ||
String continuationCondition | ||
String executionType = 'PARALLEL' | ||
|
||
List<PhaseJobContext> 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 | ||
*/ | ||
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 |
||
@RequiresPlugin(id = 'jenkins-multijob-plugin', minimumVersion = '1.22') | ||
void executionType(String executionType) { | ||
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 |
||
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. | ||
* | ||
|
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 | ||
|
@@ -227,9 +232,25 @@ class MultiJobStepContextSpec extends Specification { | |
thrown(DslScriptException) | ||
} | ||
|
||
def 'call phase with unsupported execution type'(String execution) { | ||
setup: | ||
jobManagement.isMinimumPluginVersionInstalled('jenkins-multijob-plugin', '1.22') >> true | ||
|
||
when: | ||
context.phase('test') { | ||
executionType execution | ||
} | ||
|
||
then: | ||
thrown(DslScriptException) | ||
|
||
where: | ||
execution << ['FOO'] | ||
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 |
||
} | ||
|
||
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,16 +259,40 @@ 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 | ||
} | ||
|
||
where: | ||
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 << ['SEQUENTIALLY'] | ||
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 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 needs to be wrapped in an if block testing
jobManagement.isMinimumPluginVersionInstalled(...)
so that the new element only gets generated if the minimum required plugin version is installed.