# After the Deploy

Course: [CI/CD](https://www.devtutorials.ai/learn/cicd) · Section: Running Pipelines Well
Source: https://www.devtutorials.ai/learn/cicd/running-pipelines-well/after-the-deploy

> Tell the team when a run fails, set alerts that are quiet but quick, read debug logs, run on Windows when you must, and keep the runner bill small.

## After the Deploy

The release is live. The pipeline is green. The work is not over.

- A run on main can fail at night, and nobody looks at the Actions tab.
- Production can slowly break an hour after the smoke test passed.
- A step can be skipped, and the log does not say why.
- The runner bill can double without anyone noticing.

You will add messages, alerts, debug logs and cost checks.

**Simple lesson:** a pipeline you cannot see is a pipeline you cannot trust.

### A Real-World Example

Think about a school water tank.

- A float alarm rings when the tank is nearly empty. Nobody needs to climb up and look.
- But if it rings every time the water ripples, people start ignoring it.
- When the pump stops, the caretaker opens the cover and checks each pipe.
- The school also checks the electricity bill each month.

Now map it:

- **Alarm** = an alert on production.
- **Rings too often** = a noisy alert.
- **Opening the cover** = debug logging.
- **Electricity bill** = runner minutes.

**Simple lesson:** be told when it matters, see inside when it breaks, and watch the bill.

## Tell the Team When It Breaks

- Email from GitHub or Azure goes to the person who pushed. Others never see it.
- A message in the team chat reaches everyone.
- Send it **only on failure**, from the last step.

| Platform | Step | Condition |
|---|---|---|
| GitHub Actions | `slackapi/slack-github-action` | `if: failure()` |
| Azure Pipelines | a `curl` to the chat webhook | `condition: failed()` |

The webhook URL is a secret. Anyone with it can post into your channel. Store it as `SLACK_WEBHOOK_URL`, never in the YAML. Microsoft Teams and Discord work the same way with their own webhooks.

**Simple lesson:** failure messages go to the team, with the run link in them.

## Alerts on Production

A pipeline message is about the **pipeline**. An **alert** is about the **live app**.

- A tool like Azure Monitor watches a number, like the error rate.
- An alert rule has a **threshold** (how bad) and a **window** (for how long).
- A small window fires on every blip. People stop reading it.
- A big window, or a high threshold, fires too late, or never.

**Simple lesson:** an alert must be quiet on a normal day and loud within minutes of a real problem.

## Turn On Debug Logging

When a step is skipped or a value is empty, the normal log may not say why.

| Platform | Turn on debug logs |
|---|---|
| GitHub Actions | **Re-run jobs → Enable debug logging**, or a variable `ACTIONS_STEP_DEBUG: true` |
| Azure Pipelines | **Run pipeline → Enable system diagnostics**, or a variable `system.debug: true` |

To try a GitHub workflow on your laptop, use **act** (`nektos/act`). It runs jobs in Docker. It is good for quick checks, but it is not a perfect copy of GitHub's runners.

**Simple lesson:** debug logs show why each step ran or was skipped.

## Runners and Cost

- GitHub-hosted runners for private repos are billed by the minute.
- Windows minutes cost **2 times** Linux. macOS costs **10 times**.
- Public repos and self-hosted runners are not billed this way.
- Azure Pipelines bills by **parallel jobs**, not minutes.

Run on Windows only the jobs that need it:

A **self-hosted runner** is your own machine. It is cheaper for heavy builds, but you must patch it. Never use one for public repos: a pull request from anyone could run code on it.

**Simple lesson:** pick the cheapest runner that does the job.

1. Create a Slack incoming webhook (or a Teams one) for a test channel.
2. Add it as the repository secret `SLACK_WEBHOOK_URL`.
3. Add the "Tell the team" step to your test job.
4. Break a test, push to main, then undo it.

**What you should see:** one message in the channel with a link that opens the failed run.

## Quick Check

## Cheat Sheet

GitHub Actions:

```yaml
jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - run: npm run lint

  test:
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - run: npm test
      - name: Tell the team
        if: failure()
        uses: slackapi/slack-github-action@v2
        with:
          webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
          webhook-type: incoming-webhook
          payload: |
            text: "CI failed on ${{ github.ref_name }}: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
```

Azure Pipelines:

```yaml
variables:
  system.debug: false

jobs:
  - job: test
    strategy:
      matrix:
        linux:
          imageName: ubuntu-latest
        windows:
          imageName: windows-latest
    pool:
      vmImage: $(imageName)
    steps:
      - script: npm test
      - script: |
          curl -X POST -H 'Content-type: application/json' --data '{"text":"Pipeline failed: $(System.CollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)"}' $(SLACK_WEBHOOK_URL)
        condition: failed()
```

## Common mistakes

| Mistake | Wrong idea | Correct idea | What goes wrong |
|---|---|---|---|
| Message on every run | More news is better | Only on failure | People mute the channel |
| Message with no link | "Failed" is enough | Link to the run | People waste time finding it |
| Webhook URL in YAML | It is only a URL | It is a secret | Anyone can post in your channel |
| Alert window of 1 minute | Faster is safer | Average a few minutes | False alarms all day |
| Everything on Windows | It is the same | Windows costs 2 times | The bill doubles |
| Debug logging always on | More logs help | Turn it on to investigate | Huge, slow logs |

## What to Remember

- Failure messages: last step, `failure()` or `failed()`, with a run link, to the team chat.
- Alerts watch the live app: a threshold and a window, quiet but quick.
- Debug logs show why steps ran or were skipped.
- Linux by default. Windows or macOS only where needed.

## Exercises

Next: **Delivery Metrics**
