Search code examples
jsongoogle-cloud-platformyamlwebhooksgoogle-cloud-build

How do I pass a substitution value from a webhook payload for Cloud Build?


The Google Cloud Build - Webhook Trigger documentation shows the proper URL to POST to invoke the build trigger. However the documentation does not describe how to pass a value from a webhook JSON payload to a substitution variable. Can we pass substitution variables in the POST body? This is my JSON body :

{

  "substitutions": {

    "projectId": "ABC",

    "repoName": "XYZ"

  }

}

This is my inline YAML build file for Cloud Build :

steps:
  - name: maven
    args:
      - '-c'
      - >-
        echo "SUB1:${_SUB_ONE} SUB2:${_SUB_TWO} PROJECT_ID:$PROJECT_ID
        REPO_NAME:$REPO_NAME"
    entrypoint: bash
substitutions:
  _SUB_ONE: '${body.substitutions.projectId}'
  _SUB_TWO: '${body.substitutions.repoName}'

${_SUB_ONE} and ${_SUB_TWO} does not populate the values "ABC" and "XYZ" respectively in the echo statement.

Output of the echo statement:

SUB1: SUB2: PROJECT_ID:dev REPO_NAME:itemdetails

Solution

  • Looks like you have to use $(body) instead of ${body}. For ex :$(body.substitutions.projectId)