In this example, I know the destination environment from $BITBUCKET_BRANCH in my step set-deployment-environment. I set my environment variable $ENV_NAME, but deployment will not accept an environment variable as I believe this needs to be a string.
pull-requests:
release/*:
- step: *set-deployment-environment
- step:
<<: *ansible-build-deploy
name: Deploying to environment
deployment: $ENV_NAME
Can anyone suggest a solution?
Hello @Mach Dinh-Vu ,
Thank you for reaching out to Atlassian Community!
Unfortunately, it's currently not possible to define a dynamic environment in the YML file using environment variables. The deployment environment of the step needs to be a fixed static value that was previously created under the Deployments section of Repository Settings. We do have an open feature request to implement the ability for deployment environments to be configured dynamically/using env variable, which you can find below :
I would suggest you to add your vote there, since this helps both developers and product managers to understand the interest. Also, make sure you add yourself as a watcher in case you want to receive first-hand updates from that ticket. Please note that all features are implemented with this policy in mind.
Thank you, @Mach Dinh-Vu !
Patrik S
You can set the deployment environment in steps and stages. To accomplish deployment environments per merge branch, I added stages. It solves the build/deploy scenario for branches (see branches: below).
Unfortunately, it doesn't help if you want to pick a deployment environment based on target branch in the case of a Pull Request.
Suggestion: Not ideal, but you could accomplish it with branch naming conventions (e.g. release/prod-* would set the deployment to production).
pipelines:
pull-requests:
'release/dev-*':
- stage:
name: Pull Request Validation Build
deployment: dev
steps:
- parallel:
- step: *security_scan
- step: *build
- step: *terraform_plan
'release/prod-*':
- stage:
name: Pull Request Validation Build
deployment: prod
steps:
- parallel:
- step: *security_scan
- step: *build
- step: *terraform_plan
branches:
development:
- stage:
name: Build and deploy
deployment: dev
steps:
- parallel:
- step: *security_scan
- step: *build
- step: *terraform_plan
- step: *terraform_apply
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.