https://github.com/joscha/buildkite-failed-builds-notifier
A Buildkite webhook that sends out an email to people that potentially have failed a build
https://github.com/joscha/buildkite-failed-builds-notifier
buildkite webtask
Last synced: 5 months ago
JSON representation
A Buildkite webhook that sends out an email to people that potentially have failed a build
- Host: GitHub
- URL: https://github.com/joscha/buildkite-failed-builds-notifier
- Owner: joscha
- Created: 2018-04-08T05:00:39.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-07T10:55:16.000Z (almost 3 years ago)
- Last Synced: 2025-03-31T15:17:44.894Z (6 months ago)
- Topics: buildkite, webtask
- Language: JavaScript
- Homepage:
- Size: 99.6 KB
- Stars: 8
- Watchers: 2
- Forks: 3
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Bilbo, the buildkite failed builds notifier
A [Buildkite](http://www.buildkite.com) webhook that sends out an email to people that potentially have failed a build.It looks like this:
Failures stack:
until the build passes, at which the culprits are reset.
It uses the [Buildkite webhooks](https://buildkite.com/docs/webhooks/integrations) and [webtask.io](https://webtask.io/).
## Assumptions
* The culprits are stored per pipeline, so only one branch can be used for each pipeline, e.g. `master`. If you want to track culprits between builds in multiple branches, you need to set up separate webtasks.
* Only the current person triggering the Buildkite pipeline will be notified, assuming all others have been notified in the builds before. This will not work for commits which use `[skip ci]` or `[ci skip]`.
* Pipelines are tracked with their organization, so you can use one webtask with multiple organizations, even if you have pipelines with the same name.
* The commit shas, the commit message, the email and name of the triggering person and some other data is stored in the webtask storage. For what is stored, [see here](https://github.com/joscha/buildkite-failed-builds-notifier/blob/92d7b4f63a79c123127a61d64683df3ce74047cc/failed-builds-notification.js#L80-L89).
* TODO: in case an older build on the same pipeline that is passed after failure (by reruns for example), it removes the recorded failed state currently. Ideally the state would be kept, from the failing build upwards.## Installation
Via [wt-cli](https://github.com/auth0/wt-cli):```sh
wt create https://raw.githubusercontent.com/joscha/buildkite-failed-builds-notifier/master/failed-builds-notification.js \
--name bilbo \
--secret SENDGRID_API_TOKEN= \
--secret MANDRILL_API_KEY= \
--secret BUILDKITE_TOKEN= \
--secret SENDER_EMAIL_ADDRESS=me@domain.com \
--dependency github-url-from-git@1.5.0 \
--dependency sendgrid@5.2.3
```You need either `SENDGRID_API_TOKEN` or `MANDRILL_API_KEY`. If both given, Mandrill will be preferred.
## Needed modules
```sh
wt modules add github-url-from-git@1.5.0
wt modules add sendgrid@5.2.3
wt modules add mandrill-api@1.0.45
```## Needed secrets:
* Either `SENDGRID_API_TOKEN`: Create a [new API token](https://app.sendgrid.com/settings/api_keys) and give it full access for `Mail Send`:
![]()
* Or: `MANDRILL_API_KEY`: Create a new [API key](https://www.mandrill.com/)* `BUILDKITE_TOKEN`: from your Buildkite [webhook settings](https://buildkite.com/organizations/your-org/services/webhook/new):
![]()
* `SENDER_EMAIL_ADDRESS`: The email address that is used by the email provider to generate the build fail emails.## Email settings
### Sendgrid
#### Disable click tracking
![]()
otherwise the URLs in the plain text email become really long.#### Enable plain content
![]()
otherwise the plain text will be automatically converted to HTML by sendgrid and the formatting will be off.## Buildkite webhook settings
### Enable the `ping` and `build.finished` events:
## Test
You can test the webtask with this snippet:
```json
{
"event": "build.finished",
"build": {
"web_url": "https://buildkite.com/some-org/some-pipeline/builds/1",
"number": 1,
"state": "failed",
"message": "Some build message",
"commit": "c0ffeec0ffeec0ffeec0ffeec0ffeec0ffeec0ff",
"creator": {
"name": "Mister Test",
"email": "your@email.com"
}
},
"pipeline": {
"name": "Some pipeline",
"url": "https://api.buildkite.com/v2/organizations/some-org/pipelines/some-pipeline",
"slug": "some-pipeline",
"repository": "git@github.com:some/repo.git"
}
}
```> Important: Be sure to replace `your@email.com` with your own email, to actually receive anything.
Don't forget to send this as JSON (`Content-Type: application/json`) and also pass your Buildkite token via the `X-Buildkite-Token` header. You can replace `"state": "failed"` with `"state": "passed"` to simulate a passed build run.