Overview
Send Cloud Build results to Callgoose SQIBS. Cloud Build publishes every build update to Pub/Sub; the Cloud Build HTTP notifier, a small Cloud Run service, turns the ones you choose into a JSON POST to your SQIBS API endpoint. SQIBS opens an incident when a triggered build fails and resolves it when the same trigger builds successfully.
How it works
FAILURE opens it, SUCCESS on the same trigger closes it.Want SQIBS to fix known issues before anyone is paged? See Fix known issues automatically.
Step 1: Add the API filter in SQIBS
- In SQIBS, open Services, choose the service that should receive these incidents, and click Add Or Update API Integration.
- Add a filter with these values (there is no built-in Cloud Build template yet, so enter them by hand):
| Part | Payload JSON key | Key value contains | What it does |
|---|---|---|---|
| Trigger | "status" |
FAILURE |
Opens an incident for a failed build. |
| Resolve | "status" |
SUCCESS |
Resolves the open incident. |
| Match | "triggerId" |
Ties the next build of the same trigger to the incident. | |
| Title from | "logUrl" |
Links straight to the build log. |
- Choose the Priority for these incidents and click Save.
To page on timeouts too, add a second filter with the same values and TIMEOUT instead of FAILURE. (Values in one Key value contains must all match, so each status needs its own filter.)
Not sure of a key? Send one test message first (step below), then build the filter from the real payload.
In the API Integration window, click the round
{} button at the bottom right. Paste a payload that SQIBS received (copy it from the API log). SQIBS lists every key with its value, each with a copy button. Copy the key into Payload JSON key and the value into Key value contains. No need to read the JSON by hand.Step 2: Write the notifier config and template
- Create a Cloud Storage bucket for the notifier files.
- Save this as
callgoose-sqibs.yaml. The filter sends only builds started by a trigger that end in success, failure or timeout:
apiVersion: cloud-build-notifiers/v1
kind: HTTPNotifier
metadata:
name: callgoose-sqibs-notifier
spec:
notification:
filter: build.build_trigger_id != "" && build.status in [Build.Status.SUCCESS, Build.Status.FAILURE, Build.Status.TIMEOUT]
delivery:
url: https://<your-endpoint>/sqibs-api/v1/process?from=cloudbuild&token=<your-token>
template:
type: golang
uri: gs://BUCKET_NAME/callgoose-sqibs.json
Replace <your-endpoint> and <your-token> with the values from your SQIBS account. See how to get the endpoint URL and API tokens.
- Save this as
callgoose-sqibs.json. It is the body the notifier posts, so the filter keys in step 1 match it exactly:
{
"status": "{{.Build.Status}}",
"buildId": "{{.Build.Id}}",
"triggerId": "{{.Build.BuildTriggerId}}",
"projectId": "{{.Build.ProjectId}}",
"logUrl": "{{.Build.LogUrl}}"
}
Step 3: Deploy the notifier
Run these with your bucket, project, Cloud Run service URL and the Pub/Sub service account (the Cloud Build docs show how to grant it the Cloud Run Invoker role):
gcloud storage cp callgoose-sqibs.yaml callgoose-sqibs.json gs://BUCKET_NAME/
gcloud run deploy callgoose-sqibs-notifier \
--image=us-east1-docker.pkg.dev/gcb-release/cloud-build-notifiers/http:latest \
--no-allow-unauthenticated \
--update-env-vars=CONFIG_PATH=gs://BUCKET_NAME/callgoose-sqibs.yaml,PROJECT_ID=PROJECT_ID
gcloud pubsub topics create cloud-builds
gcloud pubsub subscriptions create callgoose-sqibs-builds \
--topic=cloud-builds \
--push-endpoint=SERVICE_URL \
--push-auth-service-account=SUB_IDENTITY_SERVICE_ACCOUNT@PROJECT_ID.iam.gserviceaccount.com
Step 4: Test it
The API log saves payloads only while API Tracking is on for the token. Turn it on under API Tokens before you test; it switches itself off after 48 hours.
- Run a trigger whose build fails, for example by pushing a commit that breaks a test.
- In SQIBS, a new incident opens. The payload looks like this:
{
"status": "FAILURE",
"buildId": "6b1a7c2e-0f3d-4b8e-9a51-2d7c0e4f9a10",
"triggerId": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
"projectId": "shop-prod",
"logUrl": "https://console.cloud.google.com/cloud-build/builds/6b1a7c2e-0f3d-4b8e-9a51-2d7c0e4f9a10?project=shop-prod"
}
- Fix the build and run the trigger again. When it ends in
SUCCESS, SQIBS resolves the incident.
No incident? Open the API log (with API Tracking on). If the payload is there, the filter did not match it: paste it into the JSON key creator and check the keys. If it is not there, check the URL and token in the notifier config (and the Cloud Run logs).
Fix known issues automatically
Many alerts have a known fix: restart a service, clear a full disk, run a health check. SQIBS can run that fix for you the moment the incident opens. This is event-driven auto remediation. For example, when a deploy build fails, SQIBS can run a workflow that checks the running service and rolls it back to the last good revision.
Safe by design. SQIBS runs only workflows your own engineers wrote and approved for your environment. Nothing is guessed or generated: the same steps an engineer would run by hand, run sooner. If the workflow does not fix the issue, the engineer is paged as usual.
To set it up, in the same API filter:
- Select Workflow: choose the automation workflow to run when this filter opens an incident.
- If success then make incident resolved: turn on to resolve the incident when the workflow succeeds.
- Waiting time for escalate to escalation policies: how many minutes to give the workflow before paging the on-call engineer.
Start with low-risk workflows, such as a health check, and add fixes as you come to trust them.
Learn more:
- Prometheus: incident auto remediation, a full worked example.
- Automation workflow: build a workflow from actions.
- Run workflows where your systems are: SSH, Bash, PowerShell, Python, Ansible, kubectl, Terraform.