How to pass environment variables to the app.yaml using cloud build
Asked Answered
G

1

3

The final step of my CI/CD is the deployment using gcloud app deploy, but I can't commit the app.yaml with my environment variables, so how to deploy using cloud build passing the env variables do the app.yaml?

Here is my cloudbuild.yaml

steps:
- name: "gcr.io/cloud-builders/gcloud"
  args: ["app", "deploy"]
timeout: "1800s"
Gloat answered 27/11, 2018 at 15:28 Comment(0)
L
11

One easy option is to have your environment variables listed in a file (or even the app.yaml file itself) in Cloud Storage. You can then use the cloud-builders/gsutil to retrieve this file in a build step like this:

steps:
- name: gcr.io/cloud-builders/gsutil
  args: ['cp', 'gs://mybucket/env_vars.txt', 'env_vars.txt']

This will copy the file to the /workspace directory. The next build step can then populate the app.yaml file with the environment variables (or even just copy the retrieved app.yaml file to the correct path). The next and final step would the one you mentioned to deploy the app.

Note that, when executed in the Cloud Build environment, commands are executed with credentials of the builder service account for the project. You'll need to grant access to the file on Cloud Storage to that service account.

Leeland answered 27/11, 2018 at 15:55 Comment(1)
Hey, thanks for this comment - really useful! How would you go about populating the app.yaml file? I was trying to simply copy/overwrite the initial app.yaml used to deploy but the overwrite doesn't seem to be happening. Thanks!Despoliation

© 2022 - 2024 — McMap. All rights reserved.