In my .travis.yml
configuration, I'd like to set up deployment to different stages (development/production) depending on the branch that triggered the build. I'm using a shell script to deploy, i.e., the script
provider.
The question: I need to pass a different environment variables for different stages (mostly AWS keys). And these variables need to be encrypted when stored in version control. So, I'd like to do something like this:
deploy:
- provider: script
script: ./deploy.sh development
env:
-secure: <encrypted AWS_* variables for dev>
on:
branch: master
- provider: script
script: ./deploy.sh production
env:
-secure: <encrypted AWS_* variables for prod>
on:
branch: release
The env
key can be used only globally, however. Is it possible somehow to specify the environment only for the specific script and not anything else?
On the Windows taskbar, right-click the Windows icon and select System. In the Settings window, under Related Settings, click Advanced system settings. On the Advanced tab, click Environment Variables. Click New to create a new environment variable.
The easiest way to set environment variables in Bash is to use the “export” keyword followed by the variable name, an equal sign and the value to be assigned to the environment variable.
You accomplish this by restricting an environment variable to a specific branch when you define it using the repository settings in the web interface (I don't know how to do this using your .travis.yaml
). You can create multiple variables with the same name so long as they are restricted to different branches. In your case, create AWS_SECRET_FOO
for master
with your dev credential and AWS_SECRET_FOO
for release
with your production credential.
Regardless, it would be awesome if you could define deployment-specific env vars simply for convenience.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With