Created
May 10, 2019 11:58
-
-
Save mkutz/9c365d6bb48240b3cb8ca125eb67b5c1 to your computer and use it in GitHub Desktop.
Configure Slack in Jenkins using a post-initialization script (https://wiki.jenkins.io/display/JENKINS/Post-initialization+script)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static com.cloudbees.plugins.credentials.CredentialsScope.GLOBAL | |
import com.cloudbees.plugins.credentials.domains.Domain | |
import com.cloudbees.plugins.credentials.SystemCredentialsProvider | |
import hudson.util.Secret | |
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl | |
import com.cloudbees.plugins.credentials.CredentialsStore | |
// Configure the global Slack token as a secret text credential | |
CredentialsStore credentialsStore = SystemCredentialsProvider.getInstance().getStore() | |
StringCredentialsImpl secretTextCredentials = new StringCredentialsImpl(GLOBAL, "slack-token", "", Secret.fromString("<YOU_SLACK_TOKEN>")) // TODO add token | |
credentialsStore.addCredentials(Domain.global(), secretTextCredentials) | |
// configure the Slack plugin | |
def slack = Jenkins.instance.getExtensionList('jenkins.plugins.slack.SlackNotifier$DescriptorImpl')[0] | |
slack.with { | |
teamDomain = "<YOU_TEAM_DOMAIN>" // TODO set team domain | |
tokenCredentialId = "slack-token" | |
// token = ... // alternative: set plain token | |
// baseUrl = ... | |
// botUser = false | |
// room = ... | |
// sendAs = "Jenins" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment