问题
2019-07-04: Update
Ended up using
options:
env:
Not perfect since doesn't allow variable in build steps but atleast environments are covered.
Problem
GCP's Cloud build
is not substituting variables in substitutions
section.
Is there a way to have those substitutions applied?
Example snippet
substitutions:
_HUGO_VERSION: "0.55.6"
_HUGO_IMG: gcr.io/$PROJECT_ID/hugo:$_HUGO_VERSION
Expectation
To have $_HUGO_VERSION
and $PROJECT_ID
replaced with values, to get:
_HUGO_IMG=gcr.io/foo/hugo:0.55.6
Actual
But the value for _HUGO_IMG
is taken literally:
_HUGO_IMG=gcr.io/$PROJECT_ID/hugo:$_HUGO_VERSION
回答1:
Thanks for posting this!
Could you post the full config, when I try this I get an error for using =
instead of :
when declaring the substitutions.
The behavior I see instead is:
hugo version: 0.55.6
hugo img: gcr.io//hugo:
To interpolate default or custom substitutions, I suggest using env variables instead
steps:
- id: 'checking sub values'
name: 'gcr.io/cloud-builders/docker'
entrypoint: bash
args:
- '-c'
- |
echo 'hugo version: '${_HUGO_VERSION} # hugo version: 0.55.6
echo 'hugo img: '${_HUGO_IMG} # hugo img: gcr.io//hugo:
echo 'env hugo img: '$$HUGO_IMG # env hugo img: 'gcr.io/my-project/hugo:0.55.6'
substitutions:
_HUGO_VERSION: "0.55.6"
_HUGO_IMG: 'gcr.io/$PROJECT_ID/hugo:$_HUGO_VERSION'
options:
env:
- HUGO_IMG='gcr.io/$PROJECT_ID/hugo:$_HUGO_VERSION'
Note that env vars need to be used with $$
来源:https://stackoverflow.com/questions/56800591/cloud-build-substitutions-in-substitutions-section