To send alerts on MS teams without using any plugin you can use Curl
command or write a groovy funtion using Jenkins shared library option.
Refer - https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook
Note down the Webhook URL somewhere for later use
Refer - https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using?tabs=cURL
Example message
curl --request POST <WEBHOOK_URL> \
-H 'Content-Type: application/json' \
-d '{"text": "Hello World"}'
Secret Text
<Webhook_url>
ms_teams_webhook
Example code
script {
// Get MS Teams webhook URL from credential
withCredentials([string(credentialsId: 'ms_teams_webhook', variable: 'WEBHOOK_SECRET')]) {
// Store Webhook URL in a variable
URL_WEBHOOK = WEBHOOK_SECRET
}
// echo "$URL_WEBHOOK"
sh """#!/bin/bash
curl --location --request POST '$URL_WEBHOOK' \
--header 'Content-Type: application/json' \
--data-raw '{
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"themeColor": "bd8feb",
"summary": "Notification from [${env.JOB_NAME}]",
"sections": [{
"activityTitle": "Notification from [${env.JOB_NAME}]",
"activitySubtitle": "<span style=\'\\\'\'color: #bd8feb;\'\\\'\'>Latest status of build #${env.BUILD_NUMBER}</span>",
"activityImage": "https://www.jenkins.io/images/logos/jenkins/jenkins.png",
"facts": [
{
"name": "Pipeline",
"value": "[${env.JOB_NAME}](${env.BUILD_URL}/console)"
},
{
"name": "Git Branch",
"value": "`${GIT_BRANCH}`"
},
{
"name": "Build Number",
"value": "${env.BUILD_DISPLAY_NAME}"
},
{
"name": "Build Status",
"value": "STARTED"
},
{
"name": "Total Runtime",
"value": "${currentBuild.durationString}"
}],
"markdown": true
}],
"potentialAction": [{
"@type": "OpenUri",
"name": "View Build",
"targets": [{
"os": "default",
"uri": "${env.BUILD_URL}"
}]
}]
}'
"""
}