bashgoogle-app-enginegoogle-cloud-build

how to replace substitute string in cloudbuild.yaml


how to replace substitute string in cloudbuild.yaml?

I want to set appengine version as $TAG_NAME with cloudbuild. Since the version only accept hyphen, I need to replace the dot to hyphen first.

I tried:

steps:
- name: 'gcr.io/cloud-builders/gcloud'
  args: ['app', 'deploy', '--no-promote', "--version=$(echo $TAG_NAME | sed 's/[.]/-/g')"]
timeout: '1600s'

But got

ERROR: (gcloud.app.deploy) argument --version/-v: Bad value [$(echo 0.0.1a4 | sed 's/[.]/-/g')]: May only contain lowercase letters, digits, and hyphens. Must begin and end with a letter or digit. Must not exceed 63 characters.

Solution

  • I end up with the solution

    steps:
    - name: 'gcr.io/cloud-builders/gcloud'
      args:
      - '-c'
      - |
        version=$TAG_NAME
        gcloud app deploy --version=${version//./-}
      entrypoint: bash