How to send notification to Microsoft teams from Jenkins
In this article, we will learn how to use Jenkins Pipeline plugin to notify Microsoft Teams channel about pipeline status.
Notification is one of the key aspects of a pipeline. You don't want to keep looking at Jenkins screen to know the status. Rather you want to continue doing the next work and get an upate when the pipeline is completed.
In this article, we will learn how to use Jenkins Pipeline plugin to notify Microsoft Teams channel about pipeline status.
1. Install Office 365 Plugin on Jenkins
Installation options
- Using the GUI:
From your Jenkins dashboard navigate to Manage Jenkins > Manage Plugins and select the Available tab. Locate this plugin by searching for "Office-365-Connector". - Using the CLI tool:
jenkins-plugin-cli --plugins Office-365-Connector:4.17.0
2. Configure MS Teams Channel to send Jenkins Notification
- Create a Team channel for your notification to appear in
- Now, go to that channel, and from the top-right corner, click on 3 dot arrows and select “Connectors”
- Select “Jenkins Plugin” from the options given, click on “Add” and then “Configure” it
- Create a Name for the connection and click "Create"
- Copy the URL that is given as webhook URL and have it with you at a safe place
3. Configure your Jenkinsfile
You can configure it in two ways; Options or in a Stage
- Options at the top, where you will be notified about failure and success results at the end of the pipeline
1
2
3
4
5
6
7
8
9
10
11
pipeline {
environment {
WEB_HOOK_URL = credentials('webhook')
}
......
options {
office365ConnectorWebhooks([
[name: "Office 365", url: "${WEB_HOOK_URL}", notifyBackToNormal: true, notifyFailure: true, notifyRepeatedFailure: true, notifySuccess: true, notifyAborted: true]
])
}
}
Create a secret as a text in Jenkins and called it `webhook` and add the Webhook URL that you got from MS Teams Channel in the previous step
This will notify channel for listed statuses
- notifyFailure – Notify if the current build has failed
- notifyRepeatedFailure – Notify if 2 or more consecutive builds have failed
- notifySuccess – Notify if the current build is successful
- notifyBackToNormal – Notify if, after failed builds, the current build got successful
- notifyAborted – Notify if the build is aborted by the user
- Stage you will be notified when this stage is “Successful”, you can have failure and aborted status as well
Create a secret as a text in Jenkins and called it `webhook` and add the Webhook URL that you got from MS Teams Channel in the previous step
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
pipeline {
environment {
WEB_HOOK_URL = credentials('webhook')
}
......
stages {
stage("Deploy")
{
steps {
office365ConnectorSend webhookUrl: "${WEB_HOOK_URL}",
message: 'Code is deployed',
status: 'Success'
}
}
}
}