mon
mon

Reputation: 22254

gcp cloud build - what is _REPO_NAME variable?

Cloud Build Building Python applications example has the lines below which has _REPO_NAME variable specified.

  # [START cloudbuild_python_image_yaml]
  # Docker Build
  - name: 'gcr.io/cloud-builders/docker'
    args: ['build', '-t', 
           'us-central1-docker.pkg.dev/${PROJECT_ID}/${_REPO_NAME}/myimage:${SHORT_SHA}', '.']

The Substituting variable values documentation has $REPO_NAME: the name of your repository but does not have _REPO_NAME.

Please help understand where it is defined and what it is.

Upvotes: 1

Views: 642

Answers (1)

guillaume blaquiere
guillaume blaquiere

Reputation: 75775

With Cloud Build, all the user managed substitution variables start with _. If you variable doesn't have a _, like $REPO_NAME, it's a auto generated environment variable.


Therefore in your example you have to provide the $_REPO_NAME and $_BUCKET_NAME if you want to start your Cloud Build process. Else it will fail because it doesn't know that variable.


Why using $_REPO_NAME instead of $REPO_NAME? IMO, it's a mistake. A developer trick is to replace the auto-generated variable by a user managed variable during the tests. Like that, you don't have to push new code to git to test your build pipeline, you simply have to set that variable manually (with gcloud command).

And it might have been forgotten when that code example has been released. Just an assumption.

Upvotes: 3

Related Questions