How to set environment variables using Google Cloud Build or other method in Google App Engine Standard Environment?

后端 未结 3 1554
情深已故
情深已故 2020-12-29 15:40

Is there anyway to inject environment variables from Cloud Build into the App Engine Standard environment?

I do not want to push my environment variables to GitHub

3条回答
  •  无人及你
    2020-12-29 16:14

    I have another solution, if someone is still interested in this. This should work on all languages, because environment variables are added directly into app.yaml file

    1. Add substitution variable in build trigger (as described in this answer).

    2. Add environment variables to app.yaml in a way they can be easily substituted with build trigger variables. Like this:

        env_variables:
         SECRET_KEY: %SECRET_KEY%
    
    1. Add a step in cloudbuild.yaml to substitute all %XXX% variables inside app.yaml with their values from build trigger.
        - name: 'gcr.io/cloud-builders/gcloud'
          entrypoint: bash
          args:
          - '-c'
          - |
          sed -i 's/%SECRET_KEY%/'${_SECRET_KEY}'/g' app.yaml
          gcloud app deploy  app.yaml
    
    

提交回复
热议问题