Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Cloud Build memublikasikan pesan di topik Google Pub/Sub saat status build Anda berubah, seperti saat build dibuat, saat build bertransisi ke status yang berfungsi, dan saat build selesai. Setiap pesan berisi representasi string JSON base64
Resource build Anda di
atribut message.data. ID unik build dan
status build dapat ditemukan
di kolom message.attributes.
Secara default, pesan dipublikasikan ke topik cloud-builds; Anda juga dapat
menentukan nama topik kustom di
kolom options.pubsubTopic
file konfigurasi build. Untuk mengetahui informasi selengkapnya tentang cara mengonfigurasi nama topik
dalam file konfigurasi build, lihat
Topik Pub/Sub untuk notifikasi build.
Saat Anda mengaktifkan Cloud Build API, akun layanan Cloud Build Service Agent akan otomatis ditambahkan ke project Anda. Akun layanan memungkinkan Anda menerima notifikasi build dari Pub/Sub.
Akun layanan memiliki format berikut, dengan
project-number adalah nomor project Anda:
Jika Anda tidak melihat akun layanan Cloud Build Service Agent di halaman IAM, atau Anda tidak dapat menerima notifikasi dari Pub/Sub, ikuti langkah-langkah berikut untuk menambahkan akun layanan Cloud Build Service Agent ke project Anda:
Anda juga dapat menentukan nama topik kustom dalam file konfigurasi build
sehingga pesan dikirim ke topik kustom. Dalam hal ini, Anda
akan membuat topik dengan nama topik kustom yang sama:
Untuk mempelajari cara menyiapkan langganan Pub/Sub untuk update build,
baca Panduan Pelanggan Pub/Sub.
Anda juga dapat mempelajari
Library Klien Pub/Sub,
yang memudahkan pengembangan aplikasi subscriber.
Untuk mempelajari cara menggunakan Pub/Sub guna mengirim update build ke email atau ke layanan seperti Slack, lihat Pemberi tahu Cloud Build.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 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)."]]