Monitoring & Notifications
Job summaries, Slack alerts on failure, status badges, and if: failure() — close the feedback loop on every deployment
Skills taught: cicd.job-summaries, cicd.slack-notify, cicd.status-badges, cicd.failure-handling, cicd.observability
CI visibility — knowing what happened and why
A CI pipeline that runs silently is only half useful. When a deployment succeeds, you want your team notified so they can verify behavior in production. When it fails at 2am, the on-call engineer needs a Slack message, not an email buried in their inbox. When stakeholders ask 'is CI passing?', a badge in the README answers instantly. Visibility is the last mile of a great CI/CD setup.
Job summaries — rich reports in the GitHub UI
- name: Generate test summary
if: always() # run even if tests failed
run: |
# $GITHUB_STEP_SUMMARY is a Markdown file rendered in the workflow run UI
echo '## Test Results' >> $GITHUB_STEP_SUMMARY
echo '' >> $GITHUB_STEP_SUMMARY
# Parse test output and format as a table
PASSED=$(grep -c 'PASS' test-results.txt || echo 0)
FAILED=$(grep -c 'FAIL' test-results.txt || echo 0)
TOTAL=$((PASSED + FAILED))
echo "| Status | Count |" >> $GITHUB_STEP_SUMMARY
echo "| --- | --- |" >> $GITHUB_STEP_SUMMARY
echo "| ✅ Passed | $PASSED |" >> $GITHUB_STEP_SUMMARY
echo "| ❌ Failed | $FAILED |" >> $GITHUB_STEP_SUMMARY
echo "| 📊 Total | $TOTAL |" >> $GITHUB_STEP_SUMMARY
if [ $FAILED -gt 0 ]; then
echo '' >> $GITHUB_STEP_SUMMARY
echo '### Failed Tests' >> $GITHUB_STEP_SUMMARY
grep 'FAIL' test-results.txt >> $GITHUB_STEP_SUMMARY
fi
- name: Add deployment summary
run: |
echo "## 🚀 Deployment" >> $GITHUB_STEP_SUMMARY
echo "- **Environment:** ${{ inputs.environment }}" >> $GITHUB_STEP_SUMMARY
echo "- **URL:** ${{ steps.deploy.outputs.url }}" >> $GITHUB_STEP_SUMMARY
echo "- **Image:** \`ghcr.io/myorg/myapp:${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY
echo "- **Deployed by:** ${{ github.actor }}" >> $GITHUB_STEP_SUMMARY
Slack notifications on failure
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Deploy
id: deploy
run: ./deploy.sh
# Always runs — success or failure
- name: Notify Slack
if: always()
uses: slackapi/slack-github-action@v1
with:
payload: |
{
"text": "${{ job.status == 'success' && '✅' || '🚨' }} Deploy to ${{ inputs.environment }}",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*${{ job.status == 'success' && '✅ Deploy succeeded' || '🚨 Deploy FAILED' }}*\nEnvironment: ${{ inputs.environment }}\nBranch: ${{ github.ref_name }}\nBy: ${{ github.actor }}\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View workflow run>"
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
# Only notify on failure — for always-failing alerts on a critical service
- name: Page on-call on failure
if: failure()
run: |
curl -X POST ${{ secrets.PAGERDUTY_WEBHOOK }} \
-H 'Content-Type: application/json' \
-d '{"message": "Production deploy failed: ${{ github.run_id }}"}'
Status badges in README
<!-- Basic workflow badge -->

<!-- Badge for a specific branch -->

<!-- With link to the workflow -->
[](https://github.com/username/repo/actions/workflows/ci.yml)
<!-- Codecov coverage badge -->
[](https://codecov.io/gh/username/repo)
<!-- All badges together -->
[](https://github.com/username/repo/actions/workflows/ci.yml)
[](https://github.com/username/repo/actions/workflows/deploy.yml)
[](https://codecov.io/gh/username/repo)
Conditional steps — if: failure(), if: success(), if: always()
steps:
- name: Deploy
run: ./deploy.sh
# Runs only if ALL previous steps succeeded
- name: Run smoke tests
if: success() # this is also the default — 'if: success()' is implicit
run: ./smoke-test.sh
# Runs only if a previous step failed
- name: Rollback on failure
if: failure()
run: ./rollback.sh --version ${{ env.PREVIOUS_VERSION }}
# Runs regardless of whether previous steps succeeded or failed
- name: Upload logs
if: always()
uses: actions/upload-artifact@v4
with:
name: deploy-logs
path: logs/
# Runs if a SPECIFIC step failed (using its id)
- name: Alert if deploy specifically failed
if: steps.deploy.outcome == 'failure'
run: echo "Deploy step failed specifically"
# Combine conditions:
- name: Only alert on main branch failures
if: failure() && github.ref == 'refs/heads/main'
run: ./alert.sh
Tip: Don't alert on every PR failure — only on main. Developers expect some PRs to fail CI while they're working on a fix. Notifying Slack on every PR failure creates noise that trains people to ignore alerts. Reserve Slack/PagerDuty notifications for: (1) failures on the main branch, (2) production deployment failures, (3) scheduled security scans. Use if: failure() && github.ref == 'refs/heads/main' to scope alerts correctly.
Frequently Asked Questions
How do I avoid duplicate Slack notifications when multiple jobs in a workflow fail?
Add a dedicated 'notify' job at the end of the workflow that depends on all other jobs with 'needs: [build, test, deploy]'. Give it 'if: failure()' at the job level. This job runs only if any upstream job failed, and sends a single notification summarizing the entire workflow run. It avoids one notification per job.