Cloud build: substitutions in `substitutions` section?

折月煮酒 提交于 2020-04-16 04:18:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!