Skip to content

Commit 5b6eb62

Browse files
committed
added support for FAILURE and ALWAYS continuation conditions for the MultiJob plugin, JENKINS-26744
1 parent 4e64969 commit 5b6eb62

File tree

4 files changed

+57
-4
lines changed

4 files changed

+57
-4
lines changed

docs/Home.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ Have a look at the [Jenkins Job DSL Gradle example](https://github.com/sheehan/j
2727
* Added support for [PostBuildScript Plugin](https://wiki.jenkins-ci.org/display/JENKINS/PostBuildScript+Plugin)
2828
* Added support for [Xvfb Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Xvfb+Plugin)
2929
* Enhanced support for the [Credentials Binding Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Credentials+Binding+Plugin)
30+
* Enhanced support for the [Multijob Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Multijob+Plugin)
3031
* The enum argument of `localRepository` for the Maven job and context has changed, see [[Migration]]
3132
* Added partial support for [Plot Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Plot+Plugin)
33+
* Support for the older versions of the [Multijob Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Multijob+Plugin) is deprecated, see [[Migration]]
3234
* 1.30 (March 08 2015)
3335
* Added support for [Custom Tools Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Custom+Tools+Plugin)
3436
* Added support for [Flaky Test Handler Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Flaky+Test+Handler+Plugin)

docs/Migration.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Migrating to 1.31
22

3+
### MultiJob Plugin
4+
5+
Support for version 1.15 and earlier of the MultiJob Plugin is [[deprecated|Deprecation-Policy]] and will be removed.
6+
37
### Local Maven Repository Location
48

59
The `localRepository` method with a `javaposse.jobdsl.dsl.helpers.common.MavenContext.LocalRepositoryLocation` argument

job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/step/StepContext.groovy

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -623,14 +623,22 @@ class StepContext implements Context {
623623
PhaseContext phaseContext = new PhaseContext(jobManagement, name, continuationConditionArg)
624624
ContextHelper.executeInContext(phaseClosure, phaseContext)
625625

626+
VersionNumber multiJobPluginVersion = jobManagement.getPluginVersion('jenkins-multijob-plugin')
627+
628+
Set<String> validContinuationConditions = new HashSet<String>(VALID_CONTINUATION_CONDITIONS)
629+
if (multiJobPluginVersion?.isNewerThan(new VersionNumber('1.10'))) {
630+
validContinuationConditions << 'FAILURE'
631+
}
632+
if (multiJobPluginVersion?.isNewerThan(new VersionNumber('1.15'))) {
633+
validContinuationConditions << 'ALWAYS'
634+
}
635+
626636
Preconditions.checkArgument(phaseContext.phaseName as Boolean, 'A phase needs a name')
627637
Preconditions.checkArgument(
628-
VALID_CONTINUATION_CONDITIONS.contains(phaseContext.continuationCondition),
629-
"Continuation Condition needs to be one of these values: ${VALID_CONTINUATION_CONDITIONS.join(', ')}"
638+
validContinuationConditions.contains(phaseContext.continuationCondition),
639+
"Continuation Condition needs to be one of these values: ${validContinuationConditions.join(', ')}"
630640
)
631641

632-
VersionNumber multiJobPluginVersion = jobManagement.getPluginVersion('jenkins-multijob-plugin')
633-
634642
stepNodes << new NodeBuilder().'com.tikal.jenkins.plugins.multijob.MultiJobBuilder' {
635643
phaseName phaseContext.phaseName
636644
continuationCondition phaseContext.continuationCondition

job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/helpers/step/StepContextSpec.groovy

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,45 @@ class StepContextSpec extends Specification {
10801080
thrown(IllegalArgumentException)
10811081
}
10821082

1083+
def 'call phase with unsupported condition'(String condition, String version) {
1084+
setup:
1085+
jobManagement.getPluginVersion('jenkins-multijob-plugin') >> new VersionNumber(version)
1086+
1087+
when:
1088+
context.phase('test', condition) {
1089+
}
1090+
1091+
then:
1092+
thrown(IllegalArgumentException)
1093+
1094+
where:
1095+
condition | version
1096+
'FAILURE' | '1.10'
1097+
'ALWAYS' | '1.15'
1098+
}
1099+
1100+
def 'call phase with supported condition'(String condition, String version) {
1101+
setup:
1102+
jobManagement.getPluginVersion('jenkins-multijob-plugin') >> new VersionNumber(version)
1103+
1104+
when:
1105+
context.phase('test', condition) {
1106+
}
1107+
1108+
then:
1109+
with(context.stepNodes[0]) {
1110+
name() == 'com.tikal.jenkins.plugins.multijob.MultiJobBuilder'
1111+
children().size() == 3
1112+
phaseName[0].value() == 'test'
1113+
continuationCondition[0].value() == condition
1114+
}
1115+
1116+
where:
1117+
condition | version
1118+
'FAILURE' | '1.11'
1119+
'ALWAYS' | '1.16'
1120+
}
1121+
10831122
def 'call sbt method minimal'() {
10841123
when:
10851124
context.sbt('SBT 0.12.3')

0 commit comments

Comments
 (0)