Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge remote-tracking branch 'eddyhub/JENKINS-32764'
  • Loading branch information
daspilker committed Feb 15, 2016
2 parents 3f647d3 + 279bb85 commit 3f659be
Show file tree
Hide file tree
Showing 5 changed files with 243 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/Home.md
Expand Up @@ -21,6 +21,8 @@ Browse the Jenkins issue tracker to see any [open issues](https://issues.jenkins

## Release Notes
* 1.44 (unreleased)
* Added support for the [Mattermost Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Mattermost+Plugin)
([JENKINS-32764](https://issues.jenkins-ci.org/browse/JENKINS-32764))
* 1.43 (February 13 2016)
* Add support for the [Emotional Jenkins Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Emotional+Jenkins+Plugin)
([JENKINS-32907](https://issues.jenkins-ci.org/browse/JENKINS-32907))
Expand Down
@@ -0,0 +1,25 @@
job('example') {
publishers {
mattermost {
room('foobar team')
notifySuccess()
notifyAborted()
notifyBackToNormal()
showCommitList()
}
}
}

job('example2') {
publishers {
mattermost {
endpoint('https://mattermost.my-company.de/hooks/um9hcztr1jfnzgph6397pcoeur')
icon('http://jenkins.my-company.de/static/3d886fd0/images/foobar.png')
room('foobar team')
notifySuccess()
notifyAborted()
notifyBackToNormal()
showCommitList()
}
}
}
@@ -0,0 +1,118 @@
package javaposse.jobdsl.dsl.helpers.publisher

import javaposse.jobdsl.dsl.Context

class MattermostPublisherContext implements Context {
String endpoint
String room
String icon
String customMessage
boolean notifyBuildStart
boolean notifySuccess
boolean notifyAborted
boolean notifyNotBuilt
boolean notifyUnstable
boolean notifyFailure
boolean notifyBackToNormal
boolean notifyRepeatedFailure
boolean includeTestSummary
boolean showCommitList

/**
* Sends a notification when the build starts. Defaults to {@code false}.
*/
void notifyBuildStart(boolean notifyBuildStart = true) {
this.notifyBuildStart = notifyBuildStart
}

/**
* Sends a notification when the build is successful. Defaults to {@code false}.
*/
void notifySuccess(boolean notifySuccess = true) {
this.notifySuccess = notifySuccess
}

/**
* Sends a notification when the build is aborted. Defaults to {@code false}.
*/
void notifyAborted(boolean notifyAborted = true) {
this.notifyAborted = notifyAborted
}

/**
* Sends a notification when the build is not build. Defaults to {@code false}.
*/
void notifyNotBuilt(boolean notifyNotBuilt = true) {
this.notifyNotBuilt = notifyNotBuilt
}

/**
* Sends a notification when the build is unstable. Defaults to {@code false}.
*/
void notifyUnstable(boolean notifyUnstable = true) {
this.notifyUnstable = notifyUnstable
}

/**
* Sends a notification when the build is failed. Defaults to {@code false}.
*/
void notifyFailure(boolean notifyFailure = true) {
this.notifyFailure = notifyFailure
}

/**
* Sends a notification when the build is back to normal. Defaults to {@code false}.
*/
void notifyBackToNormal(boolean notifyBackToNormal = true) {
this.notifyBackToNormal = notifyBackToNormal
}

/**
* Sends a notification when the build repeats to fail. Defaults to {@code false}.
*/
void notifyRepeatedFailure(boolean notifyRepeatedFailure = true) {
this.notifyRepeatedFailure = notifyRepeatedFailure
}

/**
* Include the test summary in the build message. Defaults to {@code false}.
*/
void includeTestSummary(boolean includeTestSummary = true) {
this.includeTestSummary = includeTestSummary
}

/**
* Include the commit list with titles and authors in the build message. Defaults to {@code false}.
*/
void showCommitList(boolean showCommitList = true) {
this.showCommitList = showCommitList
}

/**
* Configures your Mattermost incoming webhook URL.
*/
void endpoint(String endpoint) {
this.endpoint = endpoint
}

/**
* Configures the channel names to which notifications should be sent.
*/
void room(String room) {
this.room = room
}

/**
* Configures the URL to use as avatar for the message.
*/
void icon(String icon) {
this.icon = icon
}

/**
* Configures custom message that will be included with the notifications displayed.
*/
void customMessage(String customMessage) {
this.customMessage = customMessage
}
}
Expand Up @@ -1579,6 +1579,35 @@ class PublisherContext extends AbstractExtensibleContext {
}
}

/**
* Sends notifications to Mattermost.
*
* @since 1.44
*/
@RequiresPlugin(id = 'mattermost', minimumVersion = '1.5.0')
void mattermost(@DslContext(MattermostPublisherContext) Closure mattermostClosure = null) {
MattermostPublisherContext mattermostContext = new MattermostPublisherContext()
ContextHelper.executeInContext(mattermostClosure, mattermostContext)

publisherNodes << new NodeBuilder().'jenkins.plugins.mattermost.MattermostNotifier' {
startNotification(mattermostContext.notifyBuildStart)
notifySuccess(mattermostContext.notifySuccess)
notifyAborted(mattermostContext.notifyAborted)
notifyNotBuilt(mattermostContext.notifyNotBuilt)
notifyUnstable(mattermostContext.notifyUnstable)
notifyFailure(mattermostContext.notifyFailure)
notifyBackToNormal(mattermostContext.notifyBackToNormal)
notifyRepeatedFailure(mattermostContext.notifyRepeatedFailure)
includeTestSummary(mattermostContext.includeTestSummary)
showCommitList(mattermostContext.showCommitList)
includeCustomMessage(mattermostContext.customMessage as boolean)
endpoint(mattermostContext.endpoint ?: '')
room(mattermostContext.room ?: '')
icon(mattermostContext.icon ?: '')
customMessage(mattermostContext.customMessage ?: '')
}
}

/**
* Send artifacts to an SSH server (using SFTP) and/or execute commands over SSH.
*
Expand Down
Expand Up @@ -5035,6 +5035,75 @@ class PublisherContextSpec extends Specification {
1 * jobManagement.requireMinimumPluginVersion('hipchat', '0.1.9')
}
def 'mattermost notification with no options'() {
when:
context.mattermost()
then:
with(context.publisherNodes[0]) {
name() == 'jenkins.plugins.mattermost.MattermostNotifier'
children().size() == 15
endpoint[0].value() == ''
room[0].value() == ''
icon[0].value() == ''
customMessage[0].value() == ''
startNotification[0].value() == false
notifySuccess[0].value() == false
notifyAborted[0].value() == false
notifyNotBuilt[0].value() == false
notifyUnstable[0].value() == false
notifyFailure[0].value() == false
notifyBackToNormal[0].value() == false
notifyRepeatedFailure[0].value() == false
includeTestSummary[0].value() == false
showCommitList[0].value() == false
includeCustomMessage[0].value() == false
}
1 * jobManagement.requireMinimumPluginVersion('mattermost', '1.5.0')
}
def 'mattermost notification with all options'() {
when:
context.mattermost {
endpoint('one')
room('two')
icon('three')
customMessage('four')
notifyBuildStart()
notifySuccess()
notifyAborted()
notifyNotBuilt()
notifyUnstable()
notifyFailure()
notifyBackToNormal()
notifyRepeatedFailure()
includeTestSummary()
showCommitList()
}
then:
with(context.publisherNodes[0]) {
name() == 'jenkins.plugins.mattermost.MattermostNotifier'
children().size() == 15
endpoint[0].value() == 'one'
room[0].value() == 'two'
icon[0].value() == 'three'
customMessage[0].value() == 'four'
startNotification[0].value() == true
notifySuccess[0].value() == true
notifyAborted[0].value() == true
notifyNotBuilt[0].value() == true
notifyUnstable[0].value() == true
notifyFailure[0].value() == true
notifyBackToNormal[0].value() == true
notifyRepeatedFailure[0].value() == true
includeTestSummary[0].value() == true
showCommitList[0].value() == true
includeCustomMessage[0].value() == true
}
1 * jobManagement.requireMinimumPluginVersion('mattermost', '1.5.0')
}
def 'call publishOverSsh without server'() {
when:
context.publishOverSsh(null)
Expand Down

0 comments on commit 3f659be

Please sign in to comment.