Skip to content

Commit e14b267

Browse files
committed
Merge pull request #422 from CoreMedia/JENKINS-26744
JENKINS-26744
2 parents 33a171c + 3874b7a commit e14b267

File tree

8 files changed

+393
-279
lines changed

8 files changed

+393
-279
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
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package javaposse.jobdsl.dsl.helpers.step
2+
3+
import com.google.common.base.Preconditions
4+
import hudson.util.VersionNumber
5+
import javaposse.jobdsl.dsl.ContextHelper
6+
import javaposse.jobdsl.dsl.DslContext
7+
import javaposse.jobdsl.dsl.JobManagement
8+
import javaposse.jobdsl.dsl.WithXmlAction
9+
10+
class MultiJobStepContext extends StepContext {
11+
private static final List<String> VALID_CONTINUATION_CONDITIONS = ['SUCCESSFUL', 'UNSTABLE', 'COMPLETED']
12+
13+
MultiJobStepContext(JobManagement jobManagement) {
14+
super(jobManagement)
15+
}
16+
17+
/**
18+
* phaseName will have to be provided in the closure
19+
*
20+
* <com.tikal.jenkins.plugins.multijob.MultiJobBuilder>
21+
* <phaseName>name-of-phase</phaseName>
22+
* <phaseJobs>
23+
* <com.tikal.jenkins.plugins.multijob.PhaseJobsConfig>
24+
* <jobName>job-in-phase</jobName>
25+
* <currParams>true</currParams>
26+
* <exposedSCM>false</exposedSCM>
27+
* <disableJob>false</disableJob>
28+
* <configs class="empty-list"/>
29+
* <killPhaseOnJobResultCondition>FAILURE</killPhaseOnJobResultCondition>
30+
* </com.tikal.jenkins.plugins.multijob.PhaseJobsConfig>
31+
* </phaseJobs>
32+
* <continuationCondition>COMPLETED</continuationCondition>
33+
* </com.tikal.jenkins.plugins.multijob.MultiJobBuilder>
34+
*/
35+
void phase(@DslContext(PhaseContext) Closure phaseContext) {
36+
phase(null, 'SUCCESSFUL', phaseContext)
37+
}
38+
39+
void phase(String phaseName, @DslContext(PhaseContext) Closure phaseContext = null) {
40+
phase(phaseName, 'SUCCESSFUL', phaseContext)
41+
}
42+
43+
void phase(String name, String continuationConditionArg, @DslContext(PhaseContext) Closure phaseClosure) {
44+
PhaseContext phaseContext = new PhaseContext(jobManagement, name, continuationConditionArg)
45+
ContextHelper.executeInContext(phaseClosure, phaseContext)
46+
47+
VersionNumber multiJobPluginVersion = jobManagement.getPluginVersion('jenkins-multijob-plugin')
48+
49+
Set<String> validContinuationConditions = new HashSet<String>(VALID_CONTINUATION_CONDITIONS)
50+
if (multiJobPluginVersion?.isNewerThan(new VersionNumber('1.10'))) {
51+
validContinuationConditions << 'FAILURE'
52+
}
53+
if (multiJobPluginVersion?.isNewerThan(new VersionNumber('1.15'))) {
54+
validContinuationConditions << 'ALWAYS'
55+
}
56+
57+
Preconditions.checkArgument(phaseContext.phaseName as Boolean, 'A phase needs a name')
58+
Preconditions.checkArgument(
59+
validContinuationConditions.contains(phaseContext.continuationCondition),
60+
"Continuation Condition needs to be one of these values: ${validContinuationConditions.join(', ')}"
61+
)
62+
63+
stepNodes << new NodeBuilder().'com.tikal.jenkins.plugins.multijob.MultiJobBuilder' {
64+
phaseName phaseContext.phaseName
65+
continuationCondition phaseContext.continuationCondition
66+
phaseJobs {
67+
phaseContext.jobsInPhase.each { PhaseJobContext jobInPhase ->
68+
Node phaseJobNode = 'com.tikal.jenkins.plugins.multijob.PhaseJobsConfig' {
69+
jobName jobInPhase.jobName
70+
currParams jobInPhase.currentJobParameters
71+
exposedSCM jobInPhase.exposedScm
72+
if (multiJobPluginVersion?.isNewerThan(new VersionNumber('1.10'))) {
73+
disableJob jobInPhase.disableJob
74+
killPhaseOnJobResultCondition jobInPhase.killPhaseCondition
75+
}
76+
if (jobInPhase.hasConfig()) {
77+
configs(jobInPhase.configAsNode().children())
78+
} else {
79+
configs('class': 'java.util.Collections$EmptyList')
80+
}
81+
}
82+
83+
if (jobInPhase.configureClosure) {
84+
WithXmlAction action = new WithXmlAction(jobInPhase.configureClosure)
85+
action.execute(phaseJobNode)
86+
}
87+
}
88+
}
89+
}
90+
}
91+
}

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

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package javaposse.jobdsl.dsl.helpers.step
22

33
import com.google.common.base.Preconditions
4-
import hudson.util.VersionNumber
54
import javaposse.jobdsl.dsl.Context
65
import javaposse.jobdsl.dsl.ContextHelper
76
import javaposse.jobdsl.dsl.DslContext
@@ -13,10 +12,8 @@ import static com.google.common.base.Strings.isNullOrEmpty
1312
import static javaposse.jobdsl.dsl.helpers.LocalRepositoryLocation.LOCAL_TO_WORKSPACE
1413

1514
class StepContext implements Context {
16-
private static final List<String> VALID_CONTINUATION_CONDITIONS = ['SUCCESSFUL', 'UNSTABLE', 'COMPLETED']
17-
1815
final List<Node> stepNodes = []
19-
private final JobManagement jobManagement
16+
protected final JobManagement jobManagement
2017

2118
StepContext(JobManagement jobManagement) {
2219
this.jobManagement = jobManagement
@@ -593,73 +590,6 @@ class StepContext implements Context {
593590
}
594591
}
595592

596-
/**
597-
* phaseName will have to be provided in the closure
598-
*
599-
* <com.tikal.jenkins.plugins.multijob.MultiJobBuilder>
600-
* <phaseName>name-of-phase</phaseName>
601-
* <phaseJobs>
602-
* <com.tikal.jenkins.plugins.multijob.PhaseJobsConfig>
603-
* <jobName>job-in-phase</jobName>
604-
* <currParams>true</currParams>
605-
* <exposedSCM>false</exposedSCM>
606-
* <disableJob>false</disableJob>
607-
* <configs class="empty-list"/>
608-
* <killPhaseOnJobResultCondition>FAILURE</killPhaseOnJobResultCondition>
609-
* </com.tikal.jenkins.plugins.multijob.PhaseJobsConfig>
610-
* </phaseJobs>
611-
* <continuationCondition>COMPLETED</continuationCondition>
612-
* </com.tikal.jenkins.plugins.multijob.MultiJobBuilder>
613-
*/
614-
void phase(@DslContext(PhaseContext) Closure phaseContext) {
615-
phase(null, 'SUCCESSFUL', phaseContext)
616-
}
617-
618-
void phase(String phaseName, @DslContext(PhaseContext) Closure phaseContext = null) {
619-
phase(phaseName, 'SUCCESSFUL', phaseContext)
620-
}
621-
622-
void phase(String name, String continuationConditionArg, @DslContext(PhaseContext) Closure phaseClosure) {
623-
PhaseContext phaseContext = new PhaseContext(jobManagement, name, continuationConditionArg)
624-
ContextHelper.executeInContext(phaseClosure, phaseContext)
625-
626-
Preconditions.checkArgument(phaseContext.phaseName as Boolean, 'A phase needs a name')
627-
Preconditions.checkArgument(
628-
VALID_CONTINUATION_CONDITIONS.contains(phaseContext.continuationCondition),
629-
"Continuation Condition needs to be one of these values: ${VALID_CONTINUATION_CONDITIONS.join(', ')}"
630-
)
631-
632-
VersionNumber multiJobPluginVersion = jobManagement.getPluginVersion('jenkins-multijob-plugin')
633-
634-
stepNodes << new NodeBuilder().'com.tikal.jenkins.plugins.multijob.MultiJobBuilder' {
635-
phaseName phaseContext.phaseName
636-
continuationCondition phaseContext.continuationCondition
637-
phaseJobs {
638-
phaseContext.jobsInPhase.each { PhaseJobContext jobInPhase ->
639-
Node phaseJobNode = 'com.tikal.jenkins.plugins.multijob.PhaseJobsConfig' {
640-
jobName jobInPhase.jobName
641-
currParams jobInPhase.currentJobParameters
642-
exposedSCM jobInPhase.exposedScm
643-
if (multiJobPluginVersion?.isNewerThan(new VersionNumber('1.10'))) {
644-
disableJob jobInPhase.disableJob
645-
killPhaseOnJobResultCondition jobInPhase.killPhaseCondition
646-
}
647-
if (jobInPhase.hasConfig()) {
648-
configs(jobInPhase.configAsNode().children())
649-
} else {
650-
configs('class': 'java.util.Collections$EmptyList')
651-
}
652-
}
653-
654-
if (jobInPhase.configureClosure) {
655-
WithXmlAction action = new WithXmlAction(jobInPhase.configureClosure)
656-
action.execute(phaseJobNode)
657-
}
658-
}
659-
}
660-
}
661-
}
662-
663593
/**
664594
* <dk.hlyh.ciplugins.prereqbuildstep.PrereqBuilder>
665595
* <projects>project-A,project-B</projects>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
package javaposse.jobdsl.dsl.jobs
22

3+
import hudson.util.VersionNumber
4+
import javaposse.jobdsl.dsl.ContextHelper
5+
import javaposse.jobdsl.dsl.DslContext
36
import javaposse.jobdsl.dsl.Job
47
import javaposse.jobdsl.dsl.JobManagement
8+
import javaposse.jobdsl.dsl.WithXmlAction
9+
import javaposse.jobdsl.dsl.helpers.step.MultiJobStepContext
510

611
class MultiJob extends Job {
712
MultiJob(JobManagement jobManagement) {
813
super(jobManagement)
14+
15+
if (jobManagement.getPluginVersion('jenkins-multijob-plugin')?.isOlderThan(new VersionNumber('1.16'))) {
16+
jobManagement.logDeprecationWarning('support for MultiJob plugin versions 1.15 and earlier')
17+
}
18+
}
19+
20+
void steps(@DslContext(MultiJobStepContext) Closure closure) {
21+
MultiJobStepContext context = new MultiJobStepContext(jobManagement)
22+
ContextHelper.executeInContext(closure, context)
23+
24+
withXmlActions << WithXmlAction.create { Node project ->
25+
context.stepNodes.each {
26+
project / 'builders' << it
27+
}
28+
}
929
}
1030
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package javaposse.jobdsl.dsl
2+
3+
import javaposse.jobdsl.dsl.jobs.MultiJob
4+
import spock.lang.Specification
5+
6+
class MultiJobSpec extends Specification {
7+
JobManagement jobManagement = Mock(JobManagement)
8+
MultiJob job = new MultiJob(jobManagement)
9+
10+
def 'call steps'() {
11+
when:
12+
job.steps {
13+
phase('ls')
14+
}
15+
16+
then:
17+
job.node.builders[0].children()[0].name() == 'com.tikal.jenkins.plugins.multijob.MultiJobBuilder'
18+
}
19+
}

0 commit comments

Comments
 (0)