Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
enhanced support for the Stash Notifier Plugin
deprecated support for the older versions of the Stash Notifier Plugin

[FIXES JENKINS-29183]
[FIXES JENKINS-42900]
  • Loading branch information
daspilker committed Apr 12, 2017
1 parent b5146c8 commit 958ab0a
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 16 deletions.
6 changes: 6 additions & 0 deletions docs/Home.md
Expand Up @@ -29,6 +29,12 @@ Browse the Jenkins issue tracker to see any [open issues](https://issues.jenkins

## Release Notes
* 1.61 (unreleased)
* Enhanced support for the [Stash Notifier Plugin](https://wiki.jenkins-ci.org/display/JENKINS/StashNotifier+Plugin)
([JENKINS-42900](https://issues.jenkins-ci.org/browse/JENKINS-42900),
[JENKINS-29183](https://issues.jenkins-ci.org/browse/JENKINS-29183))
* Support for the older versions of the
[Stash Notifier Plugin](https://wiki.jenkins-ci.org/display/JENKINS/StashNotifier+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
8 changes: 8 additions & 0 deletions docs/Migration.md
@@ -1,3 +1,11 @@
## Migrating to 1.61

### Stash Notifier Plugin

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

## Migrating to 1.60

### Script Security
Expand Down
Expand Up @@ -1021,15 +1021,21 @@ class PublisherContext extends AbstractExtensibleContext {
*/
@RequiresPlugin(id = 'stashNotifier')
void stashNotifier(@DslContext(StashNotifierContext) Closure stashNotifierClosure = null) {
StashNotifierContext context = new StashNotifierContext()
jobManagement.logPluginDeprecationWarning('stashNotifier', '1.11.6')

StashNotifierContext context = new StashNotifierContext(jobManagement)
ContextHelper.executeInContext(stashNotifierClosure, context)

publisherNodes << new NodeBuilder().'org.jenkinsci.plugins.stashNotifier.StashNotifier' {
stashServerBaseUrl()
stashUserName()
stashUserPassword()
ignoreUnverifiedSSLPeer(false)
commitSha1(context.commitSha1)
stashServerBaseUrl(context.serverBaseUrl ?: '')
if (jobManagement.isMinimumPluginVersionInstalled('stashNotifier', '1.9.0')) {
credentialsId(context.credentialsId ?: '')
} else {
stashUserName()
stashUserPassword()
}
ignoreUnverifiedSSLPeer(context.ignoreUnverifiedSSLCertificates)
commitSha1(context.commitSha1 ?: '')
includeBuildNumberInKey(context.keepRepeatedBuilds)
}
}
Expand Down
@@ -1,13 +1,38 @@
package javaposse.jobdsl.dsl.helpers.publisher

import javaposse.jobdsl.dsl.Context
import javaposse.jobdsl.dsl.AbstractContext
import javaposse.jobdsl.dsl.JobManagement
import javaposse.jobdsl.dsl.RequiresPlugin

/**
* DSL for https://wiki.jenkins-ci.org/display/JENKINS/StashNotifier+Plugin
*/
class StashNotifierContext implements Context {
String commitSha1 = ''
boolean keepRepeatedBuilds = false
class StashNotifierContext extends AbstractContext {
String serverBaseUrl
String credentialsId
String commitSha1
boolean keepRepeatedBuilds
boolean ignoreUnverifiedSSLCertificates

protected StashNotifierContext(JobManagement jobManagement) {
super(jobManagement)
}

/**
* Sets the base URL of the Stash server to notify.
*
* @since 1.61
*/
void serverBaseUrl(String serverBaseUrl) {
this.serverBaseUrl = serverBaseUrl
}

/**
* Sets credentials for authentication with the Stash server.
*
* @since 1.61
*/
@RequiresPlugin(id = 'stashNotifier', minimumVersion = '1.9.0')
void credentialsId(String credentialsId) {
this.credentialsId = credentialsId
}

/**
* Attaches the notification to a specific commit in Stash.
Expand All @@ -23,4 +48,13 @@ class StashNotifierContext implements Context {
void keepRepeatedBuilds(boolean keepRepeatedBuilds = true) {
this.keepRepeatedBuilds = keepRepeatedBuilds
}

/**
* If set, ignores invalid or self-signed SSL certificates. Defaults to {@code false}.
*
* @sincde 1.61
*/
void ignoreUnverifiedSSLCertificates(boolean ignoreUnverifiedSSLCertificates = true) {
this.ignoreUnverifiedSSLCertificates = ignoreUnverifiedSSLCertificates
}
}
Expand Up @@ -2971,6 +2971,7 @@ class PublisherContextSpec extends Specification {
context.publisherNodes.size() == 1
with(context.publisherNodes[0]) {
name() == 'org.jenkinsci.plugins.stashNotifier.StashNotifier'
children().size() == 6
stashServerBaseUrl[0].value().empty
stashUserName[0].value().empty
stashUserPassword[0].value().empty
Expand All @@ -2979,50 +2980,113 @@ class PublisherContextSpec extends Specification {
includeBuildNumberInKey[0].value() == false
}
1 * jobManagement.requirePlugin('stashNotifier')
1 * jobManagement.logPluginDeprecationWarning('stashNotifier', '1.11.6')
}

def 'stashNotifier with configuration of all parameters'() {
when:
context.stashNotifier {
serverBaseUrl('test')
commitSha1('sha1')
keepRepeatedBuilds(true)
ignoreUnverifiedSSLCertificates(true)
}

then:
context.publisherNodes != null
context.publisherNodes.size() == 1
with(context.publisherNodes[0]) {
name() == 'org.jenkinsci.plugins.stashNotifier.StashNotifier'
stashServerBaseUrl[0].value().empty
children().size() == 6
stashServerBaseUrl[0].value() == 'test'
stashUserName[0].value().empty
stashUserPassword[0].value().empty
ignoreUnverifiedSSLPeer[0].value() == false
ignoreUnverifiedSSLPeer[0].value() == true
commitSha1[0].value() == 'sha1'
includeBuildNumberInKey[0].value() == true
}
1 * jobManagement.requirePlugin('stashNotifier')
1 * jobManagement.logPluginDeprecationWarning('stashNotifier', '1.11.6')
}

def 'stashNotifier with configuration of all parameters using defaults for boolean parameter'() {
when:
context.stashNotifier {
serverBaseUrl('test')
commitSha1('sha1')
keepRepeatedBuilds()
ignoreUnverifiedSSLCertificates()
}

then:
context.publisherNodes != null
context.publisherNodes.size() == 1
with(context.publisherNodes[0]) {
name() == 'org.jenkinsci.plugins.stashNotifier.StashNotifier'
stashServerBaseUrl[0].value().empty
children().size() == 6
stashServerBaseUrl[0].value() == 'test'
stashUserName[0].value().empty
stashUserPassword[0].value().empty
ignoreUnverifiedSSLPeer[0].value() == true
commitSha1[0].value() == 'sha1'
includeBuildNumberInKey[0].value() == true
}
1 * jobManagement.requirePlugin('stashNotifier')
1 * jobManagement.logPluginDeprecationWarning('stashNotifier', '1.11.6')
}

def 'stashNotifier with default configuration and plugin version 1.9.0'() {
setup:
jobManagement.isMinimumPluginVersionInstalled('stashNotifier', '1.9.0') >> true

when:
context.stashNotifier {
}

then:
context.publisherNodes != null
context.publisherNodes.size() == 1
with(context.publisherNodes[0]) {
name() == 'org.jenkinsci.plugins.stashNotifier.StashNotifier'
children().size() == 5
stashServerBaseUrl[0].value().empty
credentialsId[0].value().empty
ignoreUnverifiedSSLPeer[0].value() == false
commitSha1[0].value() == ''
includeBuildNumberInKey[0].value() == false
}
1 * jobManagement.requirePlugin('stashNotifier')
1 * jobManagement.logPluginDeprecationWarning('stashNotifier', '1.11.6')
}

def 'stashNotifier with configuration of all parameters and plugin version 1.9.0'() {
setup:
jobManagement.isMinimumPluginVersionInstalled('stashNotifier', '1.9.0') >> true

when:
context.stashNotifier {
serverBaseUrl('test')
credentialsId('foo')
commitSha1('sha1')
keepRepeatedBuilds(true)
ignoreUnverifiedSSLCertificates(true)
}

then:
context.publisherNodes != null
context.publisherNodes.size() == 1
with(context.publisherNodes[0]) {
name() == 'org.jenkinsci.plugins.stashNotifier.StashNotifier'
children().size() == 5
stashServerBaseUrl[0].value() == 'test'
credentialsId[0].value() == 'foo'
ignoreUnverifiedSSLPeer[0].value() == true
commitSha1[0].value() == 'sha1'
includeBuildNumberInKey[0].value() == true
}
1 * jobManagement.requirePlugin('stashNotifier')
1 * jobManagement.requireMinimumPluginVersion('stashNotifier', '1.9.0')
1 * jobManagement.logPluginDeprecationWarning('stashNotifier', '1.11.6')
}

def 'mavenDeploymentLinker with regex'() {
Expand Down

0 comments on commit 958ab0a

Please sign in to comment.