• Stars
    star
    664
  • Rank 67,903 (Top 2 %)
  • Language
    Java
  • Created about 11 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Jenkins plugin for posting notifications to a Slack channel

Slack plugin for Jenkins

Build Status Jenkins Plugin GitHub release Jenkins Plugin Installs

Provides Jenkins notification integration with Slack or Slack compatible applications like RocketChat and Mattermost.

Install Instructions for Slack

  1. Get a Slack account: https://slack.com/

  2. Configure the Jenkins integration: https://my.slack.com/services/new/jenkins-ci

  3. Install this plugin on your Jenkins server:

    1. From the Jenkins homepage navigate to Manage Jenkins
    2. Navigate to Manage Plugins,
    3. Change the tab to Available,
    4. Search for slack,
    5. Check the box next to install.

image

If you want to configure a notification to be sent to Slack for all jobs, you may want to also consider installing an additional plugin called Global Slack Notifier plugin.

Pipeline job

slackSend color: "good", message: "Message from Jenkins Pipeline"

Additionally you can pass attachments or blocks (requires bot user) in order to send complex messages, for example:

Attachments:

def attachments = [
  [
    text: 'I find your lack of faith disturbing!',
    fallback: 'Hey, Vader seems to be mad at you.',
    color: '#ff0000'
  ]
]

slackSend(channel: "#general", attachments: attachments)

Blocks (this feature requires a 'bot user' and a custom slack app):

blocks = [
	[
		"type": "section",
		"text": [
			"type": "mrkdwn",
			"text": "Hello, Assistant to the Regional Manager Dwight! *Michael Scott* wants to know where you'd like to take the Paper Company investors to dinner tonight.\n\n *Please select a restaurant:*"
		]
	],
    [
		"type": "divider"
	],
	[
		"type": "section",
		"text": [
			"type": "mrkdwn",
			"text": "*Farmhouse Thai Cuisine*\n:star::star::star::star: 1528 reviews\n They do have some vegan options, like the roti and curry, plus they have a ton of salad stuff and noodles can be ordered without meat!! They have something for everyone here"
		],
		"accessory": [
			"type": "image",
			"image_url": "https://s3-media3.fl.yelpcdn.com/bphoto/c7ed05m9lC2EmA3Aruue7A/o.jpg",
			"alt_text": "alt text for image"
		]
	]
]

slackSend(channel: "#general", blocks: blocks)

For more information about slack messages see Slack Messages Api, Slack attachments Api and Block kit

Note: the attachments API is classified as legacy, with blocks as the replacement (but blocks are only supported when using a bot user through a custom slack app).

File upload

You can upload files to slack with this plugin:

node {
  sh "echo hey > blah.txt"
  slackUploadFile filePath: "*.txt", initialComment:  "HEY HEY"
}

This feature requires botUser mode.

Threads Support

You can send a message and create a thread on that message using the pipeline step. The step returns an object which you can use to retrieve the thread ID. Send new messages with that thread ID as the target channel to create a thread. All messages of a thread should use the same thread ID.

Example:

def slackResponse = slackSend(channel: "cool-threads", message: "Here is the primary message")
slackSend(channel: slackResponse.threadId, message: "Thread reply #1")
slackSend(channel: slackResponse.threadId, message: "Thread reply #2")

This feature requires botUser mode.

Messages that are posted to a thread can also optionally be broadcasted to the channel. Set replyBroadcast: true to do so. For example:

def slackResponse = slackSend(channel: "ci", message: "Started build")
slackSend(channel: slackResponse.threadId, message: "Build still in progress")
slackSend(
    channel: slackResponse.threadId,
    replyBroadcast: true,
    message: "Build failed. Broadcast to channel for better visibility."
)

If you wish to upload a file to a thread, you can do so by specifying the channel, and the timestamp of the thread you want to add the file to, separated by a colon. For example:

def slackResponse = slackSend(channel: "cool-threads", message: "Here is the primary message")
sh "echo hey > blah.txt"
slackUploadFile(channel: "cool-threads:" + slackResponse.ts, filePath: "*.txt", initialComment:  "A file, inside a thread.")

Update Messages

You can update the content of a previously sent message using the pipeline step. The step returns an object which you can use to retrieve the timestamp and channelId NOTE: The slack API requires the channel ID for chat.update calls.

Example:

def slackResponse = slackSend(channel: "updating-stuff", message: "Here is the primary message")
slackSend(channel: slackResponse.channelId, message: "Update message now", timestamp: slackResponse.ts)

This feature requires botUser mode.

Emoji Reactions

Add an emoji reaction to a previously-sent message like this:

Example:

def slackResponse = slackSend(channel: "emoji-demo", message: "Here is the primary message")
slackResponse.addReaction("thumbsup")

image

You can remove an emoji reaction to a previously-sent message like this:

Example:

def slackResponse = slackSend(channel: "emoji-demo", message: "Here is the primary message")
slackResponse.addReaction("thumbsup")
// ... do some stuff
slackResponse.removeReaction("thumbsup")

This may only work reliably in channels (as opposed to private messages) due to limitations in the Slack API (See "Post to an IM channel").

This does not currently work in a situation where Jenkins is restarted between sending the initial message and adding the reaction. If this is something you need, please file an issue.

This feature requires botUser mode and the reactions:write API scope.

Unfurling Links

You can allow link unfurling if you send the message as text. This only works in a text message, as attachments cannot be unfurled.

Example:

slackSend(channel: "news-update", message: "https://www.nytimes.com", sendAsText: true)

User Id Look Up

There are two pipeline steps available to help with user id look up.

A user id can be resolved from a user's email address with the slackUserIdFromEmail step.

Example:

def userId = slackUserIdFromEmail('[email protected]')
slackSend(color: "good", message: "<@$userId> Message from Jenkins Pipeline")

A list of user ids can be resolved against the set of changeset commit authors with the slackUserIdsFromCommitters step.

Example:

def userIds = slackUserIdsFromCommitters()
def userIdsString = userIds.collect { "<@$it>" }.join(' ')
slackSend(color: "good", message: "$userIdsString Message from Jenkins Pipeline")

This feature requires botUser mode and the users:read and users:read.email API scopes.

Colors

Warning: This functionality is not supported if you are using the blocks layout mode

Any hex triplet (i.e. '#AA1100') can be used for the color of the message. There are also three builtin color options:

Name Color
good green
warning yellow
danger red

Freestyle job

  1. Configure it in your Jenkins job (and optionally as global configuration) and add it as a Post-build action.

Install Instructions for Slack compatible application

  1. Log into the Slack compatible application.
  2. Create a Webhook (it may need to be enabled in system console) by visiting Integrations.
  3. You should now have a URL with a token. Something like https://mydomain.com/hooks/xxxx where xxxx is the integration token and https://mydomain.com/hooks/ is the Slack compatible app URL.
  4. Install this plugin on your Jenkins server.
  5. Follow the freestyle or pipeline instructions for the slack installation instructions.

Security

Use Jenkins Credentials and a credential ID to configure the Slack integration token. It is a security risk to expose your integration token using the previous Integration Token setting.

Create a new Secret text credential:

image

Select that credential as the value for the Credential field:

image

Direct Message

You can send messages to channels or you can notify individual users via their slackbot. In order to notify an individual user, use the syntax @user_id in place of the project channel. Mentioning users by display name may work, but it is not unique and will not work if it is an ambiguous match.

User Mentions

Use the syntax <@user_id> in a message to mention users directly. See User Id Look Up for pipeline steps to help with user id look up.

Configuration as code

This plugin supports configuration as code Add to your yaml file:

credentials:
  system:
    domainCredentials:
      - credentials:
          - string:
              scope: GLOBAL
              id: slack-token
              secret: '${SLACK_TOKEN}'
              description: Slack token


unclassified:
  slackNotifier:
    teamDomain: <your-slack-workspace-name> # i.e. your-company (just the workspace name not the full url)
    tokenCredentialId: slack-token

For more details see the configuration as code plugin documentation: https://github.com/jenkinsci/configuration-as-code-plugin#getting-started

Bot user mode

There's two ways to authenticate with slack using this plugin.

  1. Using the "Jenkins CI" app written by Slack, it's what is known as a 'legacy app' written directly into the slack code base and not maintained anymore.

  2. Creating your own custom "Slack app" and installing it to your workspace.

The benefit of using your own custom "Slack app" is that you get to use all of the modern features that Slack has released in the last few years to Slack apps and not to legacy apps.

These include:

  • Threading
  • File upload
  • Custom app emoji per message
  • Blocks

The bot user option is not supported if you use the Slack compatible app URL option.

Creating your app

Note: These docs may become outdated as Slack changes their website, if they do become outdated please send a PR here to update the docs.

  1. Go to https://api.slack.com/apps and click "Create New App".
  2. Pick an app name, i.e. "Jenkins" and a workspace that you'll be installing it to.
  3. Click "Create App". This will leave you on the "Basic Information" screen for your new app.
  4. Scroll down to "Display Information" and fill it out. You can get the Jenkins logo from: https://jenkins.io/artwork/.
  5. Scroll back up to "Add features and functionality".
  6. Click "Permissions" to navigate to the "OAuth & Permissions" page.
  7. Scroll down to "Scopes". Under "Bot Token Scopes"
    1. Add chat:write Scope.
    2. (optional) Add files:write Scope if you will be uploading files.
    3. (optional) Add chat:write.customize Scope if you will be sending messages with a custom username and/or avatar.
    4. (optional) Add reactions:write Scope if you will be adding reactions.
    5. (optional) Add users:read and users:read.email Scope if you will be looking users up by email.
  8. (optional) Click "App Home" in the sidebar
    1. (optional) Edit the slack display name for the bot.
    2. Return to the "OAuth & Permissions" page.
  9. At the top of the page, click "Install App to Workspace". This will generate a "Bot User OAuth Access Token".
  10. Copy the "Bot User OAuth Access Token".
  11. On Jenkins: Find the Slack configuration in "Manage Jenkins → Configure System".
    1. On Jenkins: Click "Add" to create a new "Secret text" Credential with that token.
    2. On Jenkins: Select the new "Secret text" in the dropdown.
    3. On Jenkins: Make note of the "Default channel / member id".
    4. On Jenkins: Tick the "Custom slack app bot user" option.
  12. Invite the Jenkins bot user into the Slack channel(s) you wish to be notified in.
  13. On Jenkins: Click test connection. A message will be sent to the default channel / default member.

Troubleshooting connection failure

When testing the connection, you may see errors like:

    WARNING j.p.slack.StandardSlackService#publish: Response Code: 404

There's a couple of things to try:

Have you enabled bot user mode?

If you've ticked Custom slack app bot user then try unticking it, that mode is for when you've created a custom app and installed it to your workspace instead of the default Jenkins app made by Slack

Have you set the override URL?

If you've entered something into Override url then try clearing it out, that field is only needed for slack compatible apps like mattermost.

Enable additional logging

Add a log recorder for the StandardSlackService class this should give you additional details on what's going on.

If you still can't figure it out please raise an issue with as much information as possible about your config and any relevant logs.

Developer instructions

Install Maven and JDK.

$ mvn -version | grep -v home
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T08:41:47-08:00)
Java version: 1.7.0_79, vendor: Oracle Corporation
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-65-generic", arch: "amd64", family: "unix"

Run unit tests

mvn test

Create an HPI file to install in Jenkins (HPI file will be in target/slack.hpi).

mvn clean package

More Repositories

1

jenkins

Jenkins automation server
Java
21,381
star
2

docker

Docker official jenkins repo
Dockerfile
6,144
star
3

pipeline-examples

A collection of examples, tips and tricks and snippets of scripting for the Jenkins Pipeline plugin
Groovy
4,117
star
4

blueocean-plugin

Blue Ocean is a reboot of the Jenkins CI/CD User Experience
Java
2,877
star
5

configuration-as-code-plugin

Jenkins Configuration as Code Plugin
Java
2,521
star
6

kubernetes-plugin

Jenkins plugin to run dynamic agents in a Kubernetes/Docker environment
Java
2,206
star
7

job-dsl-plugin

A Groovy DSL for Jenkins Jobs - Sweeeeet!
Groovy
1,851
star
8

pipeline-plugin

Obsolete home for Pipeline plugins
1,711
star
9

JenkinsPipelineUnit

Framework for unit testing Jenkins pipelines
Groovy
1,426
star
10

gitlab-plugin

A Jenkins plugin for interfacing with GitLab
Java
1,418
star
11

jenkinsfile-runner

A command line tool to run Jenkinsfile as a function
Java
1,137
star
12

java-client-api

A Jenkins API client for Java
Java
888
star
13

jenkins-scripts

Scripts in Groovy, shell, Ruby, Python, whatever for managing/interacting with Jenkins
Groovy
880
star
14

build-monitor-plugin

Jenkins Build Monitor Plugin
Java
722
star
15

git-plugin

Git repository access for Jenkins jobs
Java
668
star
16

pipeline-model-definition-plugin

Groovy
562
star
17

docker-workflow-plugin

Jenkins plugin which allows building, testing, and using Docker images from Jenkins Pipeline projects.
Java
500
star
18

ghprb-plugin

github pull requests builder plugin for Jenkins
Java
495
star
19

docker-plugin

Jenkins Cloud Plugin that uses Docker
Java
482
star
20

docker-inbound-agent

Docker image for a Jenkins agent which can connect to Jenkins using TCP or Websocket protocols
PowerShell
466
star
21

helm-charts

Jenkins helm charts
Mustache
448
star
22

pipeline-aws-plugin

Jenkins Pipeline Step Plugin for AWS
Java
423
star
23

jenkins.rb

Deprecated, see https://www.jenkins.io/jep/7
Ruby
394
star
24

generic-webhook-trigger-plugin

Can receive any HTTP request, extract any values from JSON or XML and trigger a job with those values available as variables. Works with GitHub, GitLab, Bitbucket, Jira and many more.
Java
377
star
25

email-ext-plugin

Jenkins Email Extension Plugin
Java
338
star
26

dingtalk-plugin

Dingtalk for jenkins
Java
336
star
27

warnings-ng-plugin

Jenkins Warnings Plugin - Next Generation
Java
323
star
28

plugin-installation-manager-tool

Plugin Manager CLI tool for Jenkins
Java
301
star
29

mesos-plugin

Mesos Cloud Jenkins Plugin
Java
290
star
30

github-plugin

Jenkins GitHub plugin
Java
286
star
31

ec2-plugin

Jenkins ec2 plugin
Java
285
star
32

ssh-steps-plugin

Jenkins pipeline steps which provides SSH facilities such as command execution or file transfer for continuous delivery.
Java
273
star
33

ansicolor-plugin

Jenkins ANSI Color Plugin
Java
252
star
34

pipeline-utility-steps-plugin

Small, miscellaneous, cross platform utility steps for Jenkins Pipeline jobs.
Java
237
star
35

docker-agent

Base Docker image for Jenkins Agents
PowerShell
231
star
36

ansible-plugin

Jenkins Ansible plugin
Java
223
star
37

workflow-cps-global-lib-plugin

Java
223
star
38

hashicorp-vault-plugin

Jenkins plugin to populate environment variables from secrets stored in HashiCorp's Vault.
Java
218
star
39

lib-file-leak-detector

Java agent that detects file handle leak
Java
217
star
40

bitbucket-branch-source-plugin

Bitbucket Branch Source Plugin
Java
213
star
41

gerrit-trigger-plugin

Java
212
star
42

remoting

Jenkins Remoting module
Java
212
star
43

workflow-aggregator-plugin

211
star
44

android-emulator-plugin

Android Emulator plugin for Jenkins
Java
207
star
45

docker-slaves-plugin

A Jenkins plugin to run builds inside Docker containers
Java
205
star
46

github-branch-source-plugin

GitHub Branch Source Plugin
Java
205
star
47

pipeline-stage-view-plugin

Visualizes Jenkins pipelines
JavaScript
204
star
48

jenkinsfile-runner-github-actions

Jenkins single-shot pipeline execution in a GitHub Action POC
Shell
199
star
49

amazon-ecs-plugin

Amazon EC2 Container Service Plugin for Jenkins
Java
193
star
50

trilead-ssh2

Patched trilead-ssh2 used in Jenkins
Java
193
star
51

cucumber-reports-plugin

Jenkins plugin to generate cucumber-jvm reports
Java
192
star
52

docker-build-publish-plugin

Java
192
star
53

performance-plugin

Performance Test Running and Reporting for Jenkins CI
Java
190
star
54

jira-plugin

Jenkins jira plugin
Java
169
star
55

gitea-plugin

This plugin provides the Jenkins integration for Gitea.
Java
168
star
56

embeddable-build-status-plugin

Embed build status of Jenkins jobs in web pages
Java
167
star
57

stashnotifier-plugin

A Jenkins Plugin to notify Atlassian Stash|Bitbucket of build results
Java
163
star
58

docker-ssh-agent

Docker image for Jenkins agents connected over SSH
PowerShell
162
star
59

workflow-cps-plugin

Java
160
star
60

http-request-plugin

This plugin does a request to an url with some parameters.
Java
154
star
61

kubernetes-pipeline-plugin

Kubernetes Pipeline is Jenkins plugin which extends Jenkins Pipeline to provide native support for using Kubernetes pods, secrets and volumes to perform builds
Java
154
star
62

stapler

Stapler web framework
Java
154
star
63

tfs-plugin

Jenkins tfs plugin
Java
145
star
64

jep

Jenkins Enhancement Proposals
Shell
144
star
65

kubernetes-cd-plugin

A Jenkins plugin to deploy to Kubernetes cluster
Java
140
star
66

jacoco-plugin

Jenkins JaCoCo Plugin
Java
139
star
67

qy-wechat-notification-plugin

企业微信Jenkins构建通知插件
Java
138
star
68

swarm-plugin

Jenkins swarm plugin
Java
135
star
69

git-client-plugin

Git client API for Jenkins plugins
Java
130
star
70

dependency-check-plugin

Jenkins plugin for OWASP Dependency-Check. Inspects project components for known vulnerabilities (e.g. CVEs).
Java
129
star
71

subversion-plugin

Jenkins subversion plugin
Java
127
star
72

git-parameter-plugin

Jenkins plugin for chosing Revision / Tag before build
Java
121
star
73

role-strategy-plugin

Jenkins Role-Strategy plugin
Java
120
star
74

groovy-sandbox

(Deprecated) Compile-time transformer to run Groovy code in a restrictive sandbox
Java
120
star
75

jenkins-design-language

Styles, assets, and React classes for Jenkins Design Language
TypeScript
116
star
76

acceptance-test-harness

Acceptance tests cases for Jenkins and its plugins based on selenium and docker.
Java
116
star
77

publish-over-ssh-plugin

Java
115
star
78

gitlab-branch-source-plugin

A Jenkins Plugin for GitLab Multibranch Pipeline jobs and Folder Organization
Java
115
star
79

scm-sync-configuration-plugin

Jenkins scm-sync-configuration plugin
Java
115
star
80

pipeline-as-yaml-plugin

Jenkins Pipeline As Yaml Plugin
Java
114
star
81

selenium-plugin

Jenkins selenium plugin
Java
112
star
82

docker-build-step-plugin

Java
111
star
83

jira-trigger-plugin

Triggers a build when a certain condition is matched in JIRA
Groovy
111
star
84

code-coverage-api-plugin

Deprecated Jenkins Code Coverage Plugin
Java
110
star
85

gradle-plugin

Jenkins gradle plugin
Java
109
star
86

cobertura-plugin

Jenkins cobertura plugin
Java
109
star
87

credentials-plugin

Provides Jenkins with extension points to securely store, manage, and bind credentials data to other Jenkins plugins, builds, pipelines, etc.
Java
107
star
88

jira-steps-plugin

Jenkins pipeline steps for integration with JIRA.
Java
105
star
89

artifactory-plugin

Jenkins artifactory plugin
Java
104
star
90

build-flow-plugin

A plugin to manage job orchestration
Groovy
103
star
91

github-oauth-plugin

Jenkins authentication plugin using GitHub OAuth as the source.
Java
102
star
92

throttle-concurrent-builds-plugin

Java
101
star
93

pipeline-graph-view-plugin

Java
99
star
94

promoted-builds-plugin

Jenkins Promoted Builds Plugin
Java
96
star
95

ssh-slaves-plugin

SSH Build Agents Plugin for Jenkins
Java
96
star
96

github-pr-coverage-status-plugin

Nice test coverage icon for your pull requests just from Jenkins
Java
93
star
97

jenkins-test-harness

Unit test framework for Jenkins core and its plugins
Java
92
star
98

localization-zh-cn-plugin

Chinese Localization for Jenkins
HTML
91
star
99

opentelemetry-plugin

Monitor and observe Jenkins with OpenTelemetry.
Java
90
star
100

office-365-connector-plugin

Office 365 Connector plugin sends jobs status notifications to Microsoft Teams or Outlook
Java
89
star