jenkinsci/job-dsl-plugin — pull request #251 by awreece (2014-07-29 21:47:11+00:00)
Title: Add FlexiblePublish

## Overview

Adds support for the FlexiblePublish plugin, and fixes some bugs in run conditions (in particular, for the alwaysRun condition and the build status condition).

## Testing done

In addition to the included tests, we have been using this internally via the following monkey patches:

```
/*
* A condition that matches if the current build status is better than
* or equal to worstResult and worse than or equal to bestResult.
*
* Example - the following matches only successful builds.
*
* condition {
* status 'SUCCESS', 'SUCCESS'
* }
*/
RunConditionContext.metaClass.status { String worstResult, String bestResult = null ->
bestResult = bestResult ?: worstResult

def statuses = [
'SUCCESS',
'UNSTABLE',
'FAILURE',
'NOT_BUILT',
'ABORTED',
]

assert statuses.contains(worstResult)
assert statuses.contains(bestResult)

condition = new SimpleCondition(
name: 'Status',
args: ['worstResult': {
ordinal statuses.findIndexOf { it == worstResult }
}, 'bestResult': {
ordinal statuses.findIndexOf { it == bestResult }
}])
}

/*
* Unfortunately, alwaysRun doesn't work in the current version of the
* dsl plugin - it creates an AlwaysRunCondition node, rather than an
* AlwaysRun node. We fix it here.
*/
RunConditionContext.metaClass.alwaysRun { ->
condition = new AlwaysRunCondition()
}

PublisherContext.metaClass.flexible_publish { Closure closure ->
def innerContext = new FlexiblePublisherContext()
AbstractContextHelper.executeInContext(closure, innerContext)

publisherNodes << innerContext.node
}
```

With the FlexiblePublisherContext included below basically unchanged (the only difference is I added the asserts here).