Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How do I set the deployment environment based on the destination branch

Mach Dinh-Vu
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 9, 2023

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?

2 answers

1 accepted

0 votes
Answer accepted
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 11, 2023

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

0 votes
patrickv_slalom
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 17, 2024

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

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events