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 all 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,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' {
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 @@ -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) {
Expand All @@ -238,16 +251,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 << ['PARALLEL', 'SEQUENTIALLY']
}

def 'phase works inside conditionalSteps'() {
when:
context.conditionalSteps {
Expand Down