Reputation: 11077
I'm currently using AWS Amplify to manage my front-end. I've been manually injecting the environment variables throughout the console.
While I have seen that (at least in this case), the environment variables are correctly protected as mentioned in the AWS docs. I wanted to know if it was possible to set in the amplify.yml
file variables per branch that do not necessarily need protection.
Something like this:
version: 0.1
env:
variables:
myvarOne:
branch: master
value: ad
branch: dev
value otherval
frontend:
phases:
preBuild:
commands:
- yarn install
- yarn lint
- yarn test
build:
commands:
- yarn build build
artifacts:
baseDirectory: build
files:
- '**/*'
cache:
paths:
- node_modules/**/*
Upvotes: 5
Views: 4827
Reputation: 1
I'm working with the built in variable overriding in Amplify. Seems like the overridden variable is not applied when I having multiple branches connected.(In my case 2 branches- one for development and other for production)
Upvotes: 0
Reputation: 89
I might be pretty late with the answer, but as of the time of writing, it seems like there exists an out-of-the-box solution to your case.
According to the documentation almost verbatim, it asks you to do the following:
This GIF better illustrates steps 4-5.
I don't have enough stackoverflow reputation to add an image, so please refer to the 5th point in the documentation where it describes a way to Add variable override for specific branches. https://docs.aws.amazon.com/amplify/latest/userguide/environment-variables.html
Upvotes: 8
Reputation: 5322
So far, it seems there is no ideal solution for your problem However, it is possible to do some workaround to have something like that working
You cannot have per branch environment variables, but you can have per branch commands
So, you can define different variables for different branches and run the appropriate command as you wish
version: 0.1
env:
variables:
myvarOne:
value_master: val
value_dev: otherval
frontend:
phases:
preBuild:
commands:
- if [ "${AWS_BRANCH}" = "master" ]; then export VALUE=${value_master}; fi
- if [ "${AWS_BRANCH}" = "dev" ]; then export VALUE=${value_dev}; fi
- yarn install
- yarn lint
- yarn test
build:
commands:
- yarn build build
artifacts:
baseDirectory: build
files:
- '**/*'
cache:
paths:
- node_modules/**/*
Upvotes: 6