Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Read webhook parameters in cloud build

Hi, I am trigeering a cloudbuild with a webhook from GITHUB and using inline YAML. 

The documentation sed that it can be done with Substitution variables but I get error 'cloud build substitution variable "invalid character k looking for beginning of' gcoellof_0-1738182162037.png

This parameters is in payload of webhook.

Thanks in advance for any help!

0 2 178
2 REPLIES 2

Hi @gcoellof,

The issue likely came from invalid characters being passed in the webhook's payload. Below is the answer based on Google Cloud documentation.

  1. Check for Invalid Characters: Substitution variables in Cloud Build can only contain alphanumeric characters (letters and numbers) and underscores (_). Other characters like dashes (-), periods (.), or any special characters will cause errors.
  2. Using Substitution Variables: Cloud Build offers pre-defined substitutions, and you also have the option to define your own substitutions. These substitutions can be used in your build steps and images, with their values being resolved during the build process.
  3. Sanitize the Webhook Payload: If the webhook from GitHub contains invalid characters, sanitize or preprocess the payload before using it in your build steps. You can either, modify the webhook handler to clean the data. Use a script in the build to clean or replace invalid characters.

If the steps above do not work, you can contact Google Cloud Support for a more in-depth analysis. When contacting them, please provide comprehensive details and include screenshots. This will help them better understand and address your issue.

Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.

Hi, thanks for the reply, how can I Sanitize the webhook payload? or How can I get the whole payload or request payload?

When I using substitution variable I got:

gcoellof_0-1738273749173.png

Thanks in advance, I am making a case too....

With webhook payload when I try to print only $BUILD_ID and $PROJECT_ID have data:

        echo "BRANCH_NAME:-+$BRANCH_NAME+-"
        echo "_HEAD_BRANCH:-+$_HEAD_BRANCH+-"
        echo "BUILD_ID:-+$BUILD_ID+-"
        echo "PROJECT_ID:-+$PROJECT_ID+-"
        echo "REPO_NAME:-+$REPO_NAME+-"
        echo "REF_NAME:-+$REF_NAME+-"
        echo "_PUSH_NAME:-+$_PUSH_NAME+-"
        echo "_PUSH_NAME:-+$_PUSH_NAME+-"
        echo "_URL:-+$_URL+-"
        echo "_URL2:-+$_URL2+-"
        echo "_MY_VAR:-+$_MY_VAR+-"