0

I am trying to set an environment variable in a docker image via a cloudbuild.yaml for Google Cloud Build

Here is the sample cloudbuild.yaml:

steps:
      - name: "gcr.io/cloud-builders/docker"
        args: ["run", "--rm", "--volume=/foo:/bar", "--privileged", "-e FOO=bar", "my/build:latest", "/root/init_build.sh" ]
timeout: "600s"

When I run on the command line locally and pass the environment variables into the container, it works as expected. However, when I trigger a build in Cloud Build, the environment variable doesn't get set in the container.

Thank you in advance for any guidance.

1 Answers1

1

I was able to get the result I was looking for by doing the following:

steps:
  - name: "gcr.io/cloud-builders/docker"
    entrypoint: "bash"
    args: ["-c", "docker run --rm --volume=/workspace:/srv/jekyll --privileged -e FOO=bar my/build:latest /root/init_build.sh" ]
timeout: "600s"

Take a look at the Docker commandline reference and this StackOverflow post for more information

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 16 '22 at 05:39