Most of the time, when reading documentation, everything seems clear how to implement a particular piece of software. In some cases it can be very time consuming which I found out during the implementation of the Slack plugin in the OpenShift Jenkins (Ephemeral) version. One way or another I wasn’t able to send threaded messages to Slack. I finally found a working solution which I would like to share.
I assume that you already have a slack account and a working instance of OpenShift Jenkins (Ephemeral). In this case we used Jenkins (Ephemeral) version 2.89.x and Jenkins Slack Plugin version 2.14.
What’s the problem
The Jenkins Slack plugin documentation stated that you have to configure the Jenkins CI App in your Slack environment and link the App to your desired Slack channel. After installing the Slack Plugin you’re able to send messages from Jenkins to Slack. So far everything is working as documented.
I use scripted Groovy pipelines in Jenkins which will send a message to Slack when a stage is finished. When more than one pipeline is started just sending messages in sequence you will have trouble reading which message relates to which pipeline. So we want to use threaded messages. In the channel you would like to see the main message regarding the started pipeline and build and every message after that will be in this thread so it keeps the consecutive messages together. When creating threaded messages you have to have set a Slack plugin property
botUser=true so that the Jenkins CI App will use the
@slackbot user to create and update the threaded messages. I couldn’t get this to work correct!
The solution of using threaded Slack messages is easy, create your own Slack App, set the correct permission(s) and link the App to your channel.
Step 1 – Install Jenkins Slack Plugin
Step 2 – Create your Jenkins Bot App in Slack
Login with your Slack account and visit Your Apps page and click Create New App.
Create Slack App
Install App to Slack Workspace
On the top of the page OAuth & Permissions there’s a section OAuth Tokens & Redirect URLs. Click on Install App to Workspace. Confirm the installation, click Authorize.
Create Bot User
Link Jenkins Bot App to Channel
Find your Bot User OAuth Access Token
Step 3 – Groovy pipeline example
In OpenShift you now can add this example BuildConfig file. This example creates a new Jenkins Pipeline in your OpenShift namespace.
I hope this will help demystify configuring threaded messages in Slack in combination with the Jenkins Slack Plugin.
Senior Integration Specialist with over 25 years of experience in IT. Professional focus on API Management, Container-based software development / management (Redhat OpenShift) and Message-oriented middleware (Redhat JBoss Fuse / Apache Camel.