Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'JENKINS-43219'
  • Loading branch information
daspilker committed Apr 15, 2017
2 parents ad8d3d8 + 3bab58a commit 9be2fc5
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/Home.md
Expand Up @@ -29,8 +29,12 @@ Browse the Jenkins issue tracker to see any [open issues](https://issues.jenkins

## Release Notes
* 1.61 (unreleased)
* Enhanced support for the [Join Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Join+Plugin)
([JENKINS-43219](https://issues.jenkins-ci.org/browse/JENKINS-43219))
* Do not print a warning when config file name equals config file identifier
([JENKINS-43345](https://issues.jenkins-ci.org/browse/JENKINS-43345))
* Support for the older versions of the [Join Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Join+Plugin) is
deprecated, see [Migration](Migration#migrating-to-161)
* 1.60 (April 10 2017)
* Enabled script approval with the
[Script Security Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Script+Security+Plugin), see
Expand Down
7 changes: 7 additions & 0 deletions docs/Migration.md
@@ -1,3 +1,10 @@
## Migrating to 1.61

### Join Plugin

Support for versions older than 1.21 of the [Join Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Join+Plugin) is
[[deprecated|Deprecation-Policy]] and will be removed.

## Migrating to 1.60

### Script Security
Expand Down
Expand Up @@ -4,6 +4,17 @@ package javaposse.jobdsl.dsl.helpers.common
* @since 1.38
*/
class Threshold {
static final Map<String, String> THRESHOLD_COLOR_MAP = [SUCCESS: 'BLUE', UNSTABLE: 'YELLOW', FAILURE: 'RED']
static final Map<String, Integer> THRESHOLD_ORDINAL_MAP = [SUCCESS: 0, UNSTABLE: 1, FAILURE: 2]
static final Map<String, String> THRESHOLD_COLOR_MAP = [
SUCCESS: 'BLUE', UNSTABLE: 'YELLOW', FAILURE: 'RED', ABORTED: 'ABORTED'
]
static final Map<String, Integer> THRESHOLD_ORDINAL_MAP = [
SUCCESS: 0, UNSTABLE: 1, FAILURE: 2, ABORTED: 4
]

/**
* @since 1.61
*/
static final Map<String, Boolean> THRESHOLD_COMPLETED_BUILD = [
SUCCESS: true, UNSTABLE: true, FAILURE: true, ABORTED: false
]
}
Expand Up @@ -6,11 +6,15 @@ import javaposse.jobdsl.dsl.DslContext
import javaposse.jobdsl.dsl.Item
import javaposse.jobdsl.dsl.JobManagement
import javaposse.jobdsl.dsl.Preconditions
import javaposse.jobdsl.dsl.RequiresPlugin

import static javaposse.jobdsl.dsl.helpers.common.Threshold.THRESHOLD_COLOR_MAP

class JoinTriggerContext extends AbstractContext {
final List<String> projects = []
final PublisherContext publisherContext
boolean evenIfDownstreamUnstable
String resultThreshold = 'SUCCESS'

protected JoinTriggerContext(JobManagement jobManagement, Item item) {
super(jobManagement)
Expand Down Expand Up @@ -43,7 +47,26 @@ class JoinTriggerContext extends AbstractContext {
/**
* If set, runs the projects even if the downstream jobs are unstable. Defaults to {@code false}.
*/
@Deprecated
void evenIfDownstreamUnstable(boolean evenIfDownstreamUnstable = true) {
this.evenIfDownstreamUnstable = evenIfDownstreamUnstable
}

/**
* The result threshold of the downstream projects to be checked. The join projects will be started only when all
* downstream projects have results that are better then selected. Defaults to {@code 'SUCCESS'}.
*
* Possible thresholds are {@code 'SUCCESS'}, {@code 'UNSTABLE'}, {@code 'FAILURE'} or {@code 'ABORTED'}.
*
* @since 1.61
*/
@RequiresPlugin(id = 'join', minimumVersion = '1.20')
void resultThreshold(String threshold) {
Preconditions.checkArgument(
THRESHOLD_COLOR_MAP.containsKey(threshold),
"threshold must be one of these values ${THRESHOLD_COLOR_MAP.keySet().join(',')}"
)

this.resultThreshold = threshold
}
}
Expand Up @@ -16,6 +16,7 @@ import static javaposse.jobdsl.dsl.ContextHelper.toNamedNode
import static javaposse.jobdsl.dsl.Preconditions.checkArgument
import static javaposse.jobdsl.dsl.Preconditions.checkNotNullOrEmpty
import static javaposse.jobdsl.dsl.helpers.common.Threshold.THRESHOLD_COLOR_MAP
import static javaposse.jobdsl.dsl.helpers.common.Threshold.THRESHOLD_COMPLETED_BUILD
import static javaposse.jobdsl.dsl.helpers.common.Threshold.THRESHOLD_ORDINAL_MAP

@ContextType('hudson.tasks.Publisher')
Expand Down Expand Up @@ -1536,13 +1537,24 @@ class PublisherContext extends AbstractExtensibleContext {
*/
@RequiresPlugin(id = 'join', minimumVersion = '1.15')
void joinTrigger(@DslContext(JoinTriggerContext) Closure joinTriggerClosure) {
jobManagement.logPluginDeprecationWarning('join', '1.21')

JoinTriggerContext joinTriggerContext = new JoinTriggerContext(jobManagement, item)
ContextHelper.executeInContext(joinTriggerClosure, joinTriggerContext)

publisherNodes << new NodeBuilder().'join.JoinTrigger' {
joinProjects(joinTriggerContext.projects.join(', '))
joinPublishers(joinTriggerContext.publisherContext.publisherNodes)
evenIfDownstreamUnstable(joinTriggerContext.evenIfDownstreamUnstable)
if (jobManagement.isMinimumPluginVersionInstalled('join', '1.20')) {
resultThreshold {
name(joinTriggerContext.resultThreshold)
ordinal(THRESHOLD_ORDINAL_MAP[joinTriggerContext.resultThreshold])
color(THRESHOLD_COLOR_MAP[joinTriggerContext.resultThreshold])
completeBuild(THRESHOLD_COMPLETED_BUILD[joinTriggerContext.resultThreshold])
}
} else {
evenIfDownstreamUnstable(joinTriggerContext.evenIfDownstreamUnstable)
}
}
}

Expand Down
Expand Up @@ -5086,6 +5086,7 @@ class PublisherContextSpec extends Specification {
evenIfDownstreamUnstable[0].value() == false
}
1 * jobManagement.requireMinimumPluginVersion('join', '1.15')
1 * jobManagement.logPluginDeprecationWarning('join', '1.21')
}
def 'joinTrigger with all options'() {
Expand Down Expand Up @@ -5118,6 +5119,76 @@ class PublisherContextSpec extends Specification {
evenIfDownstreamUnstable[0].value() == true
}
1 * jobManagement.requireMinimumPluginVersion('join', '1.15')
1 * jobManagement.logPluginDeprecationWarning('join', '1.21')
}
def 'joinTrigger with no options and plugin version 1.20'() {
setup:
jobManagement.isMinimumPluginVersionInstalled('join', '1.20') >> true
when:
context.joinTrigger {
}
then:
with(context.publisherNodes[0]) {
name() == 'join.JoinTrigger'
children().size() == 3
joinProjects[0].value() == ''
joinPublishers[0].value().empty
with(resultThreshold[0]) {
children().size() == 4
name[0].value() == 'SUCCESS'
ordinal[0].value() == 0
color[0].value() == 'BLUE'
completeBuild[0].value() == true
}
}
1 * jobManagement.requireMinimumPluginVersion('join', '1.15')
1 * jobManagement.logPluginDeprecationWarning('join', '1.21')
}
def 'joinTrigger with all options and plugin version 1.20'() {
setup:
jobManagement.isMinimumPluginVersionInstalled('join', '1.20') >> true
when:
context.joinTrigger {
projects('one')
projects('two', 'three')
publishers {
downstreamParameterized {
trigger('upload-to-staging') {
parameters {
currentBuild()
}
}
}
}
resultThreshold('FAILURE')
}
then:
with(context.publisherNodes[0]) {
name() == 'join.JoinTrigger'
children().size() == 3
joinProjects[0].value() == 'one, two, three'
with(joinPublishers[0]) {
children().size() == 1
children()[0].name() == 'hudson.plugins.parameterizedtrigger.BuildTrigger'
children()[0].children().size() == 1
}
with(resultThreshold[0]) {
children().size() == 4
name[0].value() == 'FAILURE'
ordinal[0].value() == 2
color[0].value() == 'RED'
completeBuild[0].value() == true
}
}
1 * jobManagement.requireMinimumPluginVersion('join', '1.15')
1 * jobManagement.requireMinimumPluginVersion('join', '1.20')
1 * jobManagement.logPluginDeprecationWarning('join', '1.21')
}
def 'joinTrigger with unsupported publisher'() {
Expand Down

0 comments on commit 9be2fc5

Please sign in to comment.