How to send notification to Microsoft teams from Jenkins

How to send notification to Microsoft teams from Jenkins

Jenkins is a complete CI/CD tool that can start its process from the moment you push your latest code to Git, and end after notifying you about the success/failure/error status of your CI/CD pipeline

Notification is one of the key aspects of this pipeline, you don’t want to keep looking at Jenkins screen to know the status of your pipeline, rather you want to continue doing your next work and get an update while the pipeline is completed

In this article, we will see how to send notifications to Microsoft teams channel about pipeline status. We will configure this using Jenkins pipeline but you can achieve this using Jenkins UI configuration as well.

1. Install Office 365 Plugin for sending notification

2. Configure MS Teams Channel to send Jenkins Notification

  • Create a Team, Give it an appropriate Team name and select it to be public or private as per need
  • After creating a team, you can see Team in the left panel
    • Go to the name of the team, click on 3 dot arrows on its right side,
    • Click on “Add Channel”
  • Again, Give this channel a name and select it to be private or public channel as per your need
  • Now, go to that channel, and from the top-right corner, click on 3 dot arrows and select “Connectors” (Here there are 2 options)
    • Select “Incoming webhook” from the options given, click on “Add” and then “Configure” it (add details as name for the webhook)
    • Or Select “Jenkins Plugin” from the options given, click on “Add” and then “Configure” it
  • Copy the URL that is given as webhook URL and have it with you at a safe place

3. Configure your Jenkinsfile like below

  • In this configuration, We are configuring a plugin in options at the top, which will notify about failure and success result at the end of the pipeline
  • Here, Replace ${URL_WEBHOOK} with Webhook URL, that you got from MS Teams Channel in the previous step
  • This will notify channel for listed statuses
    • notifyFailure – Notify if current build has failed
    • notifyRepeatedFailure – Notify if 2 or more consecutive builds have failed
    • notifySuccess – Notify if current build is successful
    • notifyBackToNormal – Notify if after failed builds, current build got successful
    • notifyAborted – Notify if build is aborted by user
  • We have selected “true” for all the above status codes, thus channel will be notified if any of this happens, if you put “false” there, then it won’t be notified
pipeline {
    options {
            [name: "Office 365", url: "${URL_WEBHOOK}", notifyBackToNormal: true, notifyFailure: true, notifyRepeatedFailure: true, notifySuccess: true, notifyAborted: true]

As we are mentioning it at option at the top, without any condition, this rule will apply to all the stages in the multi-stage pipeline for all branches.

You can also add it for a particular stage and not for the full pipeline.

  • Configure it as below
pipeline {
    stages {     
            steps {
                office365ConnectorSend webhookUrl: "${URL_WEBHOOK}",
                message: 'Code is deployed',
                status: 'Success'            

Here, you will be notified when this stage is “Successful”, you can have failure and aborted status as well

We hope this article helps you share it with your team, If you face any issues configuring the same, let us know in the comment section below

Happy Learning!

Drafted On,
22nd January 2022


[Office 365 Plugin]

Also Read

How to run parallel stages in Jenkins Pipeline using Jenkinsfile

2 thoughts on “How to send notification to Microsoft teams from Jenkins”

  1. Hi,
    Actually i have to define in the multiBranch Pipeline, in Post build actions, when the stage will get failed.
    Please let me know how can we use that.

    Thanks in advance


Leave a Comment