Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
O Cloud Build publica mensagens em um tópico do Google Pub/Sub quando o estado do build muda, como quando o build é criado, quando ele começa a funcionar e quando ele é concluído. Cada mensagem contém uma representação de string JSON em base64
do recurso do build no
atributo message.data. O ID exclusivo e o
status da build estão no campo message.attributes.
Por padrão, as mensagens são publicadas no tópico cloud-builds. Também é possível
especificar um nome de tópico personalizado no campo
options.pubsubTopic
do arquivo de configuração do build. Para mais informações sobre como configurar nomes de tópicos
no arquivo de configuração do build, consulte
Tópicos do Pub/Sub para notificações de build.
Quando você ativa a API Cloud Build, a conta de serviço do Agente de serviço do
Cloud Build é adicionada automaticamente ao projeto. A
conta de serviço permite receber notificações de build do
Pub/Sub.
A conta de serviço tem o seguinte formato, em que
project-number é o número do projeto:
Se você não encontrar a conta de serviço do Agente de serviço do Cloud Build na página do IAM ou não conseguir receber notificações do Pub/Sub, siga estas etapas para adicionar a conta de serviço do Agente de serviço do Cloud Build ao seu projeto:
Também é possível definir um nome de tópico personalizado no arquivo de configuração do build
para que as mensagens sejam enviadas ao tópico personalizado. Nesse caso, você
cria um tópico com o mesmo nome de tópico personalizado:
As inscrições push entregam mensagens para um ponto de extremidade HTTP definido por você. As mensagens são entregues assim que são publicadas no tópico.
As mensagens enviadas a partir de inscrições push são assim:
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-08-18 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)."]]