Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Cloud Build publie des messages dans un sujet Google Pub/Sub lorsque l'état de la compilation change, par exemple lors de la création de la compilation, lorsque la compilation passe à un état fonctionnel et lorsque la compilation se termine. Chaque message contient une représentation de votre ressource Build sous forme de chaîne JSON encodée en base64 dans l'attribut message.data. L'ID unique de la compilation et son état sont renseignés dans le champ message.attributes.
Par défaut, les messages sont publiés dans le sujet cloud-builds. Vous pouvez également spécifier un nom de sujet personnalisé dans le champ options.pubsubTopic de votre fichier de configuration de compilation. Pour en savoir plus sur la configuration des noms de sujets dans votre fichier de configuration de compilation, consultez la section Sujets Pub/Sub pour les notifications de compilation.
Lorsque vous activez l'API Cloud Build, le compte de service Agent de service Cloud Build est automatiquement ajouté à votre projet. Le compte de service vous permet de recevoir des notifications de compilation de Pub/Sub.
Le compte de service a le format suivant, où project-number est le numéro de votre projet:
Si le compte de service de l'agent de service Cloud Build ne s'affiche pas sur votre page IAM ou si vous ne pouvez pas recevoir de notifications de Pub/Sub, procédez comme suit pour ajouter le compte de service de l'agent de service Cloud Build à votre projet:
Vous pouvez également définir un nom de sujet personnalisé dans votre fichier de configuration de compilation afin que les messages soient envoyés au sujet personnalisé. Dans ce cas, vous devez créer un sujet portant le même nom de sujet personnalisé:
Les abonnements Push envoient des messages à un point de terminaison HTTP que vous définissez. Les messages sont diffusés dès qu'ils sont publiés dans le thème.
Les messages envoyés depuis des abonnements Push se présentent comme suit :
Les abonnements Pull envoient des messages lorsqu'ils sont interrogés par l'application souscrite. Les messages sont diffusés lorsque l'abonnement est interrogé.
Les messages envoyés depuis des abonnements Pull se présentent comme suit :
Pour savoir comment configurer les abonnements Pub/Sub pour les informations de compilation, consultez le Guide pour les abonnés Pub/Sub.
Vous pouvez également en savoir plus sur les bibliothèques clientes Pub/Sub, qui facilitent le développement d'applications pour les abonnés.
Pour découvrir comment utiliser Pub/Sub pour envoyer des mises à jour de compilation par e-mail ou à des services tels que Slack, consultez la section Systèmes d'alerte Cloud Build.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (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)."]]