Cut text of variable in google cloud pipeline

Viewed 37

I am trying to bump a version automatically when deploying a project into a QA environment.

I have the following code

    args:
      - '-c'
      - |
        set -x
        npm install
        npm i -g @nrwl/cli
        npm version --git-tag-version false --commit-hooks false $(TZ=UTC0 git show --quiet --date='format-local:%Y' --format="%cd").$(TZ=UTC0 git show --quiet --date='format-local:%m%d' --format="%cd").${BUILD_ID}-${SHORT_SHA}
        nx run-many --target=build --all --configuration=qa-1 --parallel
        nx run-many --target=deploy-qa-1 --all --configuration=qa-1 --token "$$FIREBASE_TOKEN" --parallel

This works, but I would like to shorten the BUILD_ID to only 8 digits and not the full strings.

I tried using ${BUILD_ID::8} ${$(echo BUILD_ID::8)} but what I get is a empty string.

How to achieve it ?

2 Answers

Currently this is not possible in Cloud Build, you can't shorten the value of substitutions by making a substring within the args of a build.

However, if you'd like to have this implemented into Cloud Build, you can open a Feature Request into Google's Issue tracker system, so that this can be considered by their product team.

This seems to work

substitutions:
  _SHORT_BUILD: ${BUILD_ID:0:8}

then you can use ${_SHORT_BUILD}

Related