Sending build notifications

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.

The Pub/Sub topic to which Cloud Build publishes these build update messages is called cloud-builds. When you enable the Pub/Sub API, the cloud-builds topic will automatically be created for you. Each message contains a JSON representation of your Build resource, and the message's attributes field contain the build's unique ID and the build's status.

You can use a push or pull model for your Pub/Sub subscriptions.

Push

Push subscriptions deliver messages to an HTTP endpoint that you define. Messages are delivered as soon as they are published to the topic.

Messages sent from push subscriptions look like this:

{
  "message": {
    "attributes": {
      "buildId": "abcd-efgh...",
      "status": "SUCCESS"
    },
    "data": "SGVsbG8gQ2xvdWQgUHViL1N1YiEgSGVyZSBpcyBteSBtZXNzYWdlIQ==",
    "message_id": "136969346945"
  },
  "subscription": "projects/myproject/subscriptions/mysubscription"
}

Pull

Pull subscriptions deliver message when polled by the subscribed application. Messages are delivered when the subscription is polled.

Messages sent from pull subscriptions look like this:

{
  "receivedMessages": [
    {
      "ackId": "dQNNHlAbEGEIBERNK0EPKVgUWQYyODM2LwgRHFEZDDsLRk1SK...",
      "message": {
        "attributes": {
          "buildId": "abcd-efgh-...",
          "status": "SUCCESS"
        },
        "data": "SGVsbG8gQ2xvdWQgUHViL1N1YiEgSGVyZSBpcyBteSBtZXNzYWdlIQ==",
        "messageId": "19917247034"
      }
    }
  ]
}

How do I subscribe to build update notifications?

You have a variety of options for subscribing to build update notifications. for example, you can push messages to an endpoint, or write a Python app for polling your subscription.

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.

If you want to learn how to use Cloud Functions and Pub/Sub to send build updates to Slack and other third-party applications, see Configuring Notifications for Third-Party Services.

Next steps

Was this page helpful? Let us know how we did:

Send feedback about...

Cloud Build Documentation