I use drone with build on push from github. What I want to do is to push to staging
whenever anything is pushed to master
and to push to my production environment whenever anything is pushed to a branch called prod
. What I want to do is to be able to set pipeline global env variables dynamically as a build step to be able to use them with variable interpolation. As an example:
pipeline:
set_env_prod:
environment:
- env=production
when:
branch: prod
set_env_staging:
environment:
- env=staging
when:
branch: master
ecr:
docker_image: blablabla:${env}
We are very conservative with adding new syntax to the YAML that is not part of the docker-compose specification, of which Drone is a superset. So the bar is generally high for this sort of YAML change.
For the use case described in this issue I don’t think a YAML change is required. If I wanted to setup this type of workflow it would be possible using the below configuration:
pipeline:
build:
image: golang
commands:
- go build
- go test
deploy_stage:
image: plugins/ecr
region: us-east-1
access_key: xxxxxxx
secret_key: xxxxxxx
repo: xxxxxxx.dkr.ecr.us-east-1.amazonaws.com/foo
tags: staging
when:
branch: master
deploy_prod:
image: plugins/ecr
region: us-east-1
access_key: xxxxxxx
secret_key: xxxxxxx
repo: xxxxxxx.dkr.ecr.us-east-1.amazonaws.com/foo
tags: production
when:
branch: prod
If your goal is to keep things more DRY, you can do this using YAML anchors:
deployment: &deploy
image: plugins/ecr
region: us-east-1
access_key: xxxxxxx
secret_key: xxxxxxx
repo: xxxxxxx.dkr.ecr.us-east-1.amazonaws.com/foo
pipeline:
build:
image: golang
commands:
- go build
- go test
deploy_stage:
<<: *deploy
tags: staging
when:
branch: master
deploy_prod:
<<: *deploy
tags: production
when:
branch: prod
You can paste the above example into the online yaml parser to see how it works. http://yaml-online-parser.appspot.com/
Using YAML anchors is a very nice idea. Thanks!