Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add slack plugin support #1057

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1982,6 +1982,36 @@ class PublisherContext extends AbstractExtensibleContext {
}
}

@RequiresPlugin(id = 'slack', minimumVersion = '2.2')
void slackNotifier(@DslContext(SlackNotifierContext) Closure closure) {
SlackNotifierContext context = new SlackNotifierContext()
ContextHelper.executeInContext(closure, context)

publisherNodes << new NodeBuilder().'jenkins.plugins.slack.SlackNotifier' {
authToken(context.authToken)
if (context.authTokenCredentialId) {
authTokenCredentialId(context.authTokenCredentialId)
}
botUser(context.botUser)
commitInfoChoice(context.commitInfoChoice)
customMessage(context.customMessage)
includeCustomMessage(context.includeCustomMessage)
includeTestSummary(context.includeTestSummary)
notifyAborted(context.notifyAborted)
notifyBackToNormal(context.notifyBackToNormal)
notifyFailure(context.notifyFailure)
notifyNotBuilt(context.notifyNotBuilt)
notifyRegression(context.notifyRegression)
notifyRepeatedFailure(context.notifyRepeatedFailure)
notifySuccess(context.notifySuccess)
notifyUnstable(context.notifyUnstable)
room(context.room)
sendAs(context.sendAs)
startNotification(context.startNotification)
teamDomain(context.teamDomain)
}
}

@SuppressWarnings('NoDef')
protected static addStaticAnalysisContext(def nodeBuilder, StaticAnalysisContext context) {
nodeBuilder.with {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package javaposse.jobdsl.dsl.helpers.publisher

import javaposse.jobdsl.dsl.Context

class SlackNotifierContext implements Context {
String authToken
String authTokenCredentialId
boolean botUser
String commitInfoChoice
String customMessage
boolean includeCustomMessage
boolean includeTestSummary
boolean notifyAborted
boolean notifyBackToNormal
boolean notifyFailure
boolean notifyNotBuilt
boolean notifyRegression
boolean notifyRepeatedFailure
boolean notifySuccess
boolean notifyUnstable
String room
String sendAs
boolean startNotification
String teamDomain

/**
* Sets the integration token to be used to send notifications to Slack.
*/
void authToken(String authToken) {
this.authToken = authToken
}

/**
* Sets the ID for the integration token from the Credentials plugin to be used to send notifications to Slack.
*/
void authTokenCredentialId(String authTokenCredentialId) {
this.authTokenCredentialId = authTokenCredentialId
}

/**
* Indicates the token belongs to a bot user in Slack.
*/
void botUser(boolean botUser) {
this.botUser = botUser
}

void commitInfoChoice(String commitInfoChoice) {
this.commitInfoChoice = commitInfoChoice
}

/**
* Sets a custom message that will be included in the notifications.
*/
void customMessage(String customMessage) {
this.customMessage = customMessage
}

void includeCustomMessage(boolean includeCustomMessage) {
this.includeCustomMessage = includeCustomMessage
}

void includeTestSummary(boolean includeTestSummary) {
this.includeTestSummary = includeTestSummary
}

void notifyAborted(boolean notifyAborted) {
this.notifyAborted = notifyAborted
}

void notifyBackToNormal(boolean notifyBackToNormal) {
this.notifyBackToNormal = notifyBackToNormal
}

void notifyFailure(boolean notifyFailure) {
this.notifyFailure = notifyFailure
}

void notifyNotBuilt(boolean notifyNotBuilt) {
this.notifyNotBuilt = notifyNotBuilt
}

void notifyRegression(boolean notifyRegression) {
this.notifyRegression = notifyRegression
}

void notifyRepeatedFailure(boolean notifyRepeatedFailure) {
this.notifyRepeatedFailure = notifyRepeatedFailure
}

void notifySuccess(boolean notifySuccess) {
this.notifySuccess = notifySuccess
}

void notifyUnstable(boolean notifyUnstable) {
this.notifyUnstable = notifyUnstable
}

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

void sendAs(String sendAs) {
this.sendAs = sendAs
}

void startNotification(boolean startNotification) {
this.startNotification = startNotification
}

/**
* Sets the user's team Slack subdomain.
*/
void teamDomain(String teamDomain) {
this.teamDomain = teamDomain
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6192,4 +6192,17 @@ class PublisherContextSpec extends Specification {

1 * jobManagement.requireMinimumPluginVersion('log-parser', '2.0')
}

def 'call slackNotifier with no options' () {
when:
context.slackNotifier()
then:
context.publisherNodes != null
context.publisherNodes.size() == 1
with(context.publisherNodes[0]) {
name() == 'jenkins.plugins.slack.SlackNotifier'
children().size == 18
}
1 * jobManagement.requireMinimumPluginVersion('slack', '2.2')
}
}