# hkb-pipeline-failed

Fires on: A pipeline execution failed.

Run the [common pre-checks](/wiki/runbooks/#common-pre-checks) first.

## Symptoms
An email from `hkb pipeline` with the CodePipeline event: `hkb-pipeline-main` or `hkb-pipeline-site`, state `FAILED`.

## Pre-checks
1. Which stage failed: `aws codepipeline list-action-executions --profile ro-hkb-shared-services --pipeline-name <pipeline> --max-items 10`, or the CodePipeline console in Shared Services.
2. A Validate failure is in the CodeBuild log (cfn-lint, Guard, the Access Analyzer checks, gitleaks). A Plan failure is a change set that couldn't be made. An Apply failure is CloudFormation rolling back.

## Resolution
- **Validate:** fix the finding in a PR. The pipeline runs again on merge.
- **Plan or Apply:** read the stack's events in the target account for the first `FAILED` resource. Fix the template and merge; the pipeline is the only writer to the stacks it owns, so no fix is made by hand.
- **A rejected approval** also shows as a failed run. Nothing is wrong; the change waits for the next merge.

## Post-checks
The next run reaches `Succeeded`, and the site's pages return 200 in each environment it deployed to.

## Rollback
Revert the PR that broke it. The revert is a new merge and deploys like any other.

## Alert details

| Property | Value |
| --- | --- |
| Runs in | Shared Services, us-east-1 |
| Email | From `hkb pipeline`: The event itself, as JSON |
| Source | `pipeline/hkb-pipeline-foundation.yaml`, resource `FailureRule` |

The event pattern, as deployed:

```yaml
EventPattern:
  source: [aws.codepipeline]
  detail-type: [CodePipeline Pipeline Execution State Change]
  detail:
    pipeline: [!Ref PipelineName, !Ref SitePipelineName, !Ref ToolsPipelineName]
    state: [FAILED]
```
