Stay organized with collections
Save and categorize content based on your preferences.
Cloud Build publishes messages on a
Google Pub/Sub topic when your build's state changes,
such as when your build is created, when your build transitions to a working
state, and when your build completes. Each message contains a base64 JSON string
representation of your
Build resource in the
message.data attribute. The build's unique ID and the build's
status can be found
in the message.attributes field.
By default, messages are published to the cloud-builds topic; you can also
specify a custom topic name in the
options.pubsubTopic
field of your build config file. For more information about configuring topic
names in your build config file, see
Pub/Sub topics for build notifications.
When you enable the Cloud Build API, the Cloud Build Service
Agent service account is automatically added to your project. The
service account lets you receive build notifications from
Pub/Sub.
The service account has the following format, where
project-number is your project number:
If you don't see the Cloud Build Service Agent service account on your
IAM page, or you can't receive notifications from
Pub/Sub, then follow these steps to add the
Cloud Build Service Agent service account to your project:
You can also define a custom topic name in your build config file
so that messages are sent to the custom topic instead. In this case, you
would create a topic with the same custom topic name:
To learn how to set up Pub/Sub subscriptions for build updates,
read the Pub/Sub Subscriber Guide.
You can also learn about
Pub/Sub Client Libraries,
which make developing subscriber applications easier.
To learn how to use Pub/Sub to send build updates to
email or to services such as Slack, see
Cloud Build notifiers.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[[["\u003cp\u003eCloud Build sends build update messages to the \u003ccode\u003ecloud-builds\u003c/code\u003e Pub/Sub topic when a build's state changes.\u003c/p\u003e\n"],["\u003cp\u003eEach message includes a base64 JSON representation of the Build resource in \u003ccode\u003emessage.data\u003c/code\u003e and the build's ID and status in \u003ccode\u003emessage.attributes\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eYou can use either a push or pull model for your Pub/Sub subscriptions to receive these build notifications.\u003c/p\u003e\n"],["\u003cp\u003eTo receive notifications, you must enable both the Cloud Build API and the Pub/Sub API, and also add the Cloud Build Service Agent to your project.\u003c/p\u003e\n"],["\u003cp\u003eTo access information on how to set up Pub/Sub subscriptions for build updates, refer to the Pub/Sub Subscriber Guide, and Cloud Build notifiers for sending build updates to other services.\u003c/p\u003e\n"]]],[],null,["# Subscribe to build notifications\n\nCloud Build publishes messages on a\n[Google Pub/Sub](/pubsub) topic when your build's state changes,\nsuch as when your build is created, when your build transitions to a working\nstate, and when your build completes. Each message contains a base64 JSON string\nrepresentation of your\n[Build resource](/build/docs/api/reference/rest/v1/projects.builds) in the\n`message.data` attribute. The build's unique ID and the build's\n[status](/build/docs/api/reference/rest/v1/projects.builds#status) can be found\nin the `message.attributes` field.\n\nBy default, messages are published to the `cloud-builds` topic; you can also\nspecify a custom topic name in the\n[`options.pubsubTopic`](/build/docs/build-config-file-schema#pubsub-topic)\nfield of your build config file. For more information about configuring topic\nnames in your build config file, see\n[Pub/Sub topics for build notifications](/build/docs/configuring-notifications/notifiers#pubsub-topic-config).\n\nYou can use a [push or pull model](/pubsub/docs/subscriber#push_pull) for your\nPub/Sub subscriptions.\n\nReceive build notifications\n---------------------------\n\nTo receive build notifications:\n\n1. Enable the Cloud Build API:\n\n [Enable the Cloud Build API](https://console.cloud.google.com/apis/library/cloudbuild.googleapis.com)\n\n When you enable the Cloud Build API, the **Cloud Build Service\n Agent** service account is automatically added to your project. The\n service account lets you receive build notifications from\n Pub/Sub.\n\n The service account has the following format, where\n \u003cvar translate=\"no\"\u003eproject-number\u003c/var\u003e is your project number: \n\n service-\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eproject\u003c/span\u003e\u003cspan class=\"devsite-syntax-o\"\u003e-\u003c/span\u003e\u003cspan class=\"devsite-syntax-n\"\u003enumber\u003c/span\u003e\u003c/var\u003e@gcp-sa-cloudbuild.iam.gserviceaccount.com\n\n If you don't see the **Cloud Build Service Agent** service account on your\n IAM page, or you can't receive notifications from\n Pub/Sub, then follow these steps to add the\n **Cloud Build Service Agent** service account to your project:\n 1. Open the **IAM** page in the Google Cloud console:\n\n [Open the IAM page](https://console.cloud.google.com/iam-admin/iam)\n 2. Click **Grant access**.\n\n 3. Add the following principal, where \u003cvar translate=\"no\"\u003eproject-number\u003c/var\u003e\n is your project number:\n\n service-\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eproject\u003c/span\u003e\u003cspan class=\"devsite-syntax-o\"\u003e-\u003c/span\u003e\u003cspan class=\"devsite-syntax-n\"\u003enumber\u003c/span\u003e\u003c/var\u003e@gcp-sa-cloudbuild.iam.gserviceaccount.com\n\n 4. Select **Service Agents** \\\u003e **Cloud Build Service Agent** as your role.\n\n 5. Click **Save**.\n\n2. Enable the Pub/Sub API:\n\n [Enable the Pub/Sub API](https://console.cloud.google.com/apis/library/pubsub.googleapis.com)\n3. Create the `cloud-builds` topic:\n\n gcloud pubsub topics create cloud-builds\n\n You can also define a custom topic name in your build config file\n so that messages are sent to the custom topic instead. In this case, you\n would create a topic with the same custom topic name: \n\n gcloud pubsub topics create \u003cvar translate=\"no\"\u003etopic-name\u003c/var\u003e\n\n For more information, see\n [Pub/Sub topics for build notifications](/build/docs/configuring-notifications/notifiers#pubsub-topic-config).\n\n To learn more about managing Pub/Sub topics, see\n [Managing topics and subscriptions](/../pubsub/docs/admin).\n\n| **Note:** Pub/Sub notifications generated by Cloud Build are subject to the [Pub/Sub Service Level Agreement (SLA)](/../pubsub/sla).\n\nPush subscriptions\n------------------\n\n[Push subscriptions](/pubsub/docs/push) deliver messages to an HTTP endpoint\nthat you define. Messages are delivered as soon as they are published to the\ntopic.\n\nMessages sent from push subscriptions look like this: \n\n {\n \"message\": {\n \"attributes\": {\n \"buildId\": \"abcd-efgh...\",\n \"status\": \"SUCCESS\"\n },\n \"data\": \"SGVsbG8gQ2xvdWQgUHViL1N1YiEgSGVyZSBpcyBteSBtZXNzYWdlIQ==\",\n \"message_id\": \"136969346945\"\n },\n \"subscription\": \"projects/myproject/subscriptions/mysubscription\"\n }\n\nPull subscriptions\n------------------\n\n[Pull subscriptions](/pubsub/docs/pull) deliver message when polled by the\nsubscribed application. Messages are delivered when the subscription is polled.\n\nMessages sent from pull subscriptions look like this: \n\n {\n \"receivedMessages\": [\n {\n \"ackId\": \"dQNNHlAbEGEIBERNK0EPKVgUWQYyODM2LwgRHFEZDDsLRk1SK...\",\n \"message\": {\n \"attributes\": {\n \"buildId\": \"abcd-efgh-...\",\n \"status\": \"SUCCESS\"\n },\n \"data\": \"SGVsbG8gQ2xvdWQgUHViL1N1YiEgSGVyZSBpcyBteSBtZXNzYWdlIQ==\",\n \"messageId\": \"19917247034\"\n }\n }\n ]\n }\n\nSubscribe to build update notifications\n---------------------------------------\n\nYou have several options for subscribing to build update notifications.\nFor example, you can\n[push messages to an endpoint](/pubsub/docs/push#configuring-http-endpoints),\nor\n[write a Python app for polling your subscription](/pubsub/docs/pull#pubsub-pull-python).\n\nTo learn how to set up Pub/Sub subscriptions for build updates,\nread the [Pub/Sub Subscriber Guide](/pubsub/docs/subscriber).\nYou can also learn about\n[Pub/Sub Client Libraries](/pubsub/docs/reference/libraries),\nwhich make developing subscriber applications easier.\n\nTo learn how to use Pub/Sub to send build updates to\nemail or to services such as Slack, see\n[Cloud Build notifiers](/build/docs/configuring-notifications/notifiers)."]]