To send notifications from Jenkins to Microsoft Teams, you need to create an Incoming Webhook in Teams and then use that webhook URL in your Jenkins pipeline. Here's a step-by-step guide:
Yes, to send notifications to Microsoft Teams from Jenkins, you need to install the Office 365 Connector plugin. This plugin allows Jenkins to send actionable messages to Teams, Outlook, and Office 365 Groups.
Steps to Install and Configure the Plugin
1. Install the Plugin:
- Go to Manage Jenkins → Manage Plugins.
- Search for Office 365 Connector.
- Install it and restart Jenkins.
2. Configure the Webhook:
- In Microsoft Teams, create an Incoming Webhook for the channel where you want notifications.
- Copy the webhook URL.
3. Set Up in Jenkins Pipeline:
- Use the `office365ConnectorSend` step in your pipeline, as you've done.
- Ensure the webhook URL is correctly stored in Jenkins credentials.
Once configured, Jenkins will send notifications to Teams whenever a build runs. Let me know if you need help fine-tuning the setup! 🚀
✅ Step 1: Create a Webhook in Microsoft Teams
- Open Microsoft Teams and go to the channel where you want to receive Jenkins notifications.
- Click on the three dots (⋯) next to the channel name and select "Connectors".
- In the Connectors window, find and click "Incoming Webhook".
- Click "Configure" next to Incoming Webhook.
- Give your webhook a name (e.g., "Jenkins Notifications").
- (Optional) Upload an image/icon for the webhook.
- Click "Create".
- Copy the Webhook URL that is generated. It will look like:
✅ Step 2: Use the Webhook in Jenkins Pipeline
In your Jenkins pipeline script, use the office365ConnectorSend
step.
🔐 Tip: Store the webhook URL in Jenkins credentials (as a secret text) and reference it using
credentials()
for better security.
pipeline { agent any environment { TEAMS_WEBHOOK = credentials('TEAMS_WEBHOOK_URL') } stages { stage('Notify') { steps { script { office365ConnectorSend webhookUrl: "${env.TEAMS_WEBHOOK}", message: """ **Build Status:** ${currentBuild.currentResult} **Main Repo:** ${mainRepoUrl} **Main Branch:** ${mainBranch} **Build URL:** ${env.BUILD_URL} """ } } } } }
No comments:
Post a Comment