Search code examples
webhooksgoogle-cloud-build

POST body for Google Cloud Build - Webhook Triggers


The Google Cloud Build - Webhook Trigger create trigger documentation shows the proper URL to POST to invoke the build trigger. However the documentation does not describe the POST body, which seems to be required. I have successfully triggered the cloud build webhooks using content-type: application/json header with a POST body of {}, but it would be nice to know:

  • What is the POST body supposed to be?
  • Are we able to pass substitution variables in the POST body?

The Google Cloud Build - REST API documentation provides some additional hints that a HttpBody payload is accepted, but no additional information past that as for as I can tell.


Solution

  • The body is what you want! In fact, in your trigger you customize your substitution variable like this (from the documentation)

     --subtitutions=\
             _SUB_ONE='$(body.message.test)', _SUB_TWO='$(body.message.output)'
    

    So, your body need to be like that

    {
      "message": {
        "test": "test value",
        "ourput": "my output"
      }
    }
    

    The data are automatically extracted from your body content. So you can add more substitutions or change the format of your JSON and thus of your substitutions value.