Search code examples
google-cloud-platformgoogle-cloud-buildcloudbuild.yaml

GCP Cloud Build - Running Bash script with arguments


I have a GCP Cloub build configuration, where a bash script is needed to be executed.

The below configuration works just fine.

steps:
  - name: 'gcr.io/cloud-builders/gcloud'
    entrypoint: 'bash'
    args: ['./my_script.sh']

But, I want to be able to pass the Build_ID as an argument to the bash script. e.g.:

steps:
  - name: 'gcr.io/cloud-builders/gcloud'
    entrypoint: 'bash'
    args: ['./my_script.sh ${BUILD_ID}']

This doesn't work, unfortunately.

I get an error such as: bash: ./my_script.sh 204792d1-6336-489b-ba20-fbce7401a40b: No such file or directory

Any help on this is highly appreciated.


Solution

  • Try to parametrize arguments, with:

    steps:
      - name: 'gcr.io/cloud-builders/gcloud'
        entrypoint: 'bash'
        args: ['./my_script.sh', '${BUILD_ID}']