jenkins-msteams-notification
Version:
Simple webhook wrapper that uses Jenkins build environment variables to send build failure notifications to channels on Microsoft Teams
45 lines (31 loc) • 1.52 kB
Markdown
# Microsoft Teams Notifications for your failing Jenkins Build
Simple, zero-dependency, webhook wrapper that uses Jenkins build environment variables to send build failure notifications to channels on Microsoft Teams
<img width="922" alt="image" src="https://user-images.githubusercontent.com/2362668/135480146-deb63032-5223-4f8d-8ded-03b2f241635b.png">
## Usage
```sh
MSTEAMS_WEBHOOK_URL=<webhook-url> npm_config_yes=true npx jenkins-msteams-notification
```
Where `webhook-url` is a URL you create in MS Teams for the channel you'd like to notify. You can check the [Microsoft Documentation](https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook#create-incoming-webhook-1) to see how to do that.
### Example
This is ideal to include in the [`post`](https://www.jenkins.io/doc/book/pipeline/syntax/#post) section of your Jenkins pipeline. You'll need to ensure that the code is executed on an agent with `node` and `npx` available.
You might add something like this to your Jenkins pipeline:
```groovy
environment {
MSTEAMS_WEBHOOK_URL = '<url you got from the Teams client>'
}
// ... your stages, etc.
post {
failure {
container('node') {
script {
if (env.BRANCH_NAME == 'main')
sh "npm_config_yes=true npx jenkins-msteams-notification"
}
}
}
}
```
## Scope
Currently hardcoded to report a failure and has only been tested with code hosted on GitHub.
## License
MIT