Table Of Contents
- Microsoft Teams Webhook
- Adding Webhook Connector to a Channel
- Sending Messages to Webhook
- Sending Messages to Webhook from Jenkins Build
Microsoft Teams Webhook
Microsoft Team’s Incoming webhook
connector allows you to publish messages to teams channel.
You can even add actions to the content so that users can complete tasks within the channel.
Adding Webhook Connector to a Channel
In Microsoft Teams, choose the More options (⋯)
button next to the channel name in the list of channels and then choose Connectors.
Add Incoming webhook
connector to the channel.
Now choose configure
button next to the Incoming Webhook
connector.
Provide a name and upload an image for the connector. Now select Create
button.
Copy the webhook URL for later reference.
We have now set up the webhook for the channel.
Sending Messages to Webhook
To send a message to the webhook connector we have to send it as a JSON payload. Refer message card template on how the payload needs to be structured.
Note: Adaptive cards are the recommended card type for new Teams development. They are the new cross product specification for cards in Microsoft products including Bots, Cortana, Outlook, and Windows. However, they are not supported yet in teams connectors.
You can experiment your card design at Card Playground.
We will send below sample payload to the connector and check if it works.
Send this JSON payload as a POST request to the Webhook URL.
You can either use Send via WebHook
option available in the Card Playground (or) Postman to send the message to the webhook.
There is a python library which you can make use of for building the messages dynamically.
https://pypi.org/project/ms-teams/
Sending Messages to Webhook from Jenkins Build
You can make use of the office 365 connector plugin to send build messages to the webhook.
However, if you want to send a custom message as part of your jenkins job then we can’t make use of this plugin.
Below is a sample which sends a custom card message to the webhook using httpRequest
step in jenkins pipeline code.
This card shows the build parameter values with an action button to view the build job.
References:
https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/connectors
https://docs.microsoft.com/en-us/outlook/actionable-messages/actionable-messages-via-connectors