Configuring Alerts for GitHub Actions and Azure Pipelines
This lesson explains how to raise useful alerts from delivery events.
Learning outcomes
After completing this lesson, you will be able to:
- Send an alert from a workflow.
- Create notification subscriptions and service hooks.
- Subscribe Teams channels to pipeline events.
- Alert on trends, and reduce noise.
Alerts in GitHub Actions
Built-in notifications
GitHub notifies the person who triggered a workflow when it completes, according to their notification settings, and these can be limited to failed runs. This suits personal awareness, but not team-wide operations.
Notification steps
A workflow can send its own alert. A step with if: failure() runs only when an earlier step has failed. Here, a final job posts to a Teams channel through a workflow webhook.
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- run: ./deploy.sh
notify:
needs: deploy
if: failure()
runs-on: ubuntu-latest
steps:
- name: Post to the operations channel
env:
WEBHOOK: ${{ secrets.TEAMS_WEBHOOK_URL }}
run: |
curl -sf -H "Content-Type: application/json" \
-d "{\"text\":\"Deployment failed: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID\"}" \
"$WEBHOOK"Events and webhooks
The workflow_run event starts a separate workflow after another finishes, which allows one central notification workflow to watch several others. Repository or organization webhooks can send workflow_run and workflow_job events to external systems. The GitHub app for Teams can subscribe a channel to workflow notifications, with @GitHub subscribe OWNER/REPO workflows.
A failure alert that never fires
Alerts in Azure Pipelines
Notification subscriptions
Azure DevOps notifications are created in Project settings, or at team or personal level. A subscription selects an event, such as Build completes or Release deployment approval pending, adds filters such as the pipeline name and status, and delivers an email to chosen people. A team subscription suits a pipeline owned by one team.
Service hooks
Service hooks send events to external services, as explained earlier. Events include run state changed, stage state changed and approval pending. These can post to a webhook or to Azure Service Bus.
Azure Pipelines app for Teams
The Azure Pipelines app for Teams subscribes a channel to pipeline events, and an approver can respond from within the channel.
@azure pipelines signin
@azure pipelines subscribe https://dev.azure.com/contoso/payments/_build?definitionId=12
@azure pipelines subscriptionsFailure steps in YAML
A job with condition: failed() can raise an alert, or create a work item. Classic build pipelines also have a Create work items on failure option, and a YAML pipeline can create a work item through a REST call.
The following diagram shows the Azure Pipelines app in Microsoft Teams, its channel subscription and filters.

Pipeline alerts in Azure DevOps
Alerting on trends
A single failure often does not matter, but a pattern does. A rising failure rate, or queue times above a limit, may need attention before anybody complains. Exporting pipeline events to Log Analytics allows a log search alert on a trend, for example when more than 20% of runs fail within an hour. Alerts on self-hosted agents should be raised too: Azure Monitor can watch their virtual machines, and an agent that has gone offline leaves jobs waiting, which is easy to overlook.
Alerting on patterns
Reducing noise
- Alert on what matters: production and main branch failures, not every pull request.
- Send to the owner, with a link to the failed run.
- Use severity, so that a blocked production release differs from a failed nightly test.
- Remove alerts that nobody acts on.
The following table recaps the options.
| Need | GitHub Actions | Azure Pipelines |
|---|---|---|
| Notify the person who started a run | Personal notifications | Default subscriptions |
| Notify a team | GitHub app for Teams | Azure Pipelines app, or a team subscription |
| Send to any system | Webhook | Service hook |
| Custom logic after failure | if: failure() | condition: failed() |
| Alert on a trend | Export to Log Analytics | Export to Log Analytics |
Pipeline alerts on both platforms
Notifying a team
A team wants a message in its Microsoft Teams channel whenever a production Azure Pipelines deployment waits for approval or fails, and nothing for other events. What is the simplest approach?
Install the Azure Pipelines app in Teams, subscribe the channel to the pipeline, and edit the subscription to keep only approvals and failed stages. A custom script in each stage would need upkeep, and it could not report an approval wait in the same way. An email subscription would not post to the channel.
How can one GitHub workflow react to the failure of others?
Show answer
Use the workflow_run event with a completed type, and test the conclusion of the triggering run.
Exam Tips
Remember for the exam
- Use if: failure() in GitHub Actions and condition: failed() in Azure Pipelines.
- workflow_run lets one workflow react to others.
- Service hooks send pipeline events to external services.
- Team subscriptions filter by event and pipeline.
- Export events to Log Analytics to alert on trends.