Storing secrets into Bitbucket Pipelines and then deploy on App Engine?

Viewed 2911

Suppose having a project in a bitbucket repository storing a secret API key in a config file like config.json:

{
    "secret": 
}

Is it possible refer to the "secret" variable from variables in bitbucket pipeline and then deploy this automatically to google App Engine, so that App Engine "knows" the secret variable?

1 Answers

You can use envsubst command in your pipeline.

Your json file would look like this and be named config_template.json:

{
    "secret": $SECRET
}

The step in your pipline would look like this:

- step:
    name: replace secret
    script:
      # pipe config_template.json to envsubst and store result in a file called config.json
      - cat config_template.json | envsubst > config.json
      # show config.json TODO: Remove this when you are sure it is working!
      - cat config.json
      # Deploy config.json to App Engine here!

This assumes that you have envsubst in your build image and a repository variable called SECRET in your pipeline.

Related