Search code examples
dockergoogle-cloud-builddocker-buildcloudbuild.yaml

Do I need to add substituions values that I'll provide via CLI to the cloudbuild.yaml file?


In my cloudbuild.yaml file, I'm relying on a value that will be passed through the builds submit --substitutions=_SERVER_ENV=TEST command.

This is how I'm referencing it:

cloudbuild.yaml

steps:
  - name: "gcr.io/cloud-builders/docker"
    args: [
      "build",
      "--build-arg SERVER_ENV=$_SERVER_ENV",       // <----- IT WILL BE PASSED TO DOCKER --build-arg
      "."
    ]

My question is: do I need to add it to my cloudbuild.yaml file in the substitutions section?

Example:

cloudbuild.yaml

substitutions:               // DO I NEED TO ADD THIS SECTION?
  - "_SERVER_ENV=TEST"       // GIVEN THE FACT THAT I'LL BE PROVIDING IT THROUGH THE CLI

Or can I leave it out and be sure that the builder will look for it the CLI command like:

builds submit --substitutions=_SERVER_ENV=TEST


REFERENCES

DOC: gcloud builds submit

DOC: build config substitutions

DOC: build config - Substituting variable values


Solution

  • You don't need the substitutions part in the cloudbuild.yaml part. However, the value will be empty and can break your Build, or worse passes with an unstable status

    As you prefer

    • Either a build that passes with a default not critical value
    • Or a build that passes with an empty value with unknow/untested behavior.