Skip to content
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

Merged
merged 3 commits into from
Oct 10, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class MultiJobStepContext extends StepContext {
stepNodes << new NodeBuilder().'com.tikal.jenkins.plugins.multijob.MultiJobBuilder' {
phaseName phaseContext.phaseName
delegate.continuationCondition(phaseContext.continuationCondition)
delegate.executionType(phaseContext.executionType)
Copy link
Member

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.

phaseJobs {
phaseContext.jobsInPhase.each { PhaseJobContext jobInPhase ->
Node phaseJobNode = 'com.tikal.jenkins.plugins.multijob.PhaseJobsConfig' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand All @@ -19,6 +26,7 @@ class PhaseContext extends AbstractContext {
this.item = item
this.phaseName = phaseName
this.continuationCondition = continuationCondition
this.executionType = executionType
}

/**
Expand All @@ -35,6 +43,19 @@ class PhaseContext extends AbstractContext {
this.continuationCondition = continuationCondition
}

/**
* Defines how to run the whole MultiJob phase.
* @since 1.52
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a @since tag which points to the next version.

@RequiresPlugin(id = 'jenkins-multijob-plugin', minimumVersion = '1.22')
void executionType(String executionType) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feature need version 1.22 of the MultiJob plugin. Add a @RequiresPlugin annotation.

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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
Expand All @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not use a where section if there is only one option

}

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) {
Expand All @@ -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']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not use a where section if there is only one option, but you could also test both supported options here

Copy link
Author

@sanicheev sanicheev Oct 10, 2016

Choose a reason for hiding this comment

The 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 {
Expand Down