3

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.

1 Answer 1

4

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.

3
  • can you provide a link to the documentation you are referencing? Looks like this (cloud.google.com/build/docs/configuring-builds/…) might have been the missing piece of the puzzle for me.
    – jrmerz
    Mar 31, 2021 at 17:56
  • Arf, no, the doc is bad :( I was in the alpha program for the PubSub trigger. And the example is extracted from the PubSub trigger example (the pubsub message has a message structure). It's only by experience with the service and similar trigger. Your question is good, because the doc is bad. You can perform a feedback on the doc page if you want. I will forward it to the Google Cloud PM (product manager). Mar 31, 2021 at 18:43
  • 1
    OK thanks! I have already provided feedback on the Webhook Trigger documentation page. I have tested your solution and it works great, much appreciated.
    – jrmerz
    Mar 31, 2021 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.