Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,294,914
Community Members
 
Community Events
165
Community Groups

The environment '$BITBUCKET_DEPLOYMENT_ENVIRONMENT' in your bitbucket-pipelines.yml doesn’t match...

I have 2 deployments, "staging" and "production" which are compiled and deployed to S3 buckets using CI pipelines.  Currently we have a bitbucket-pipeline.yml that looks like this on our staging branch in Git:

image: node:8.12.0

pipelines:
branches:
staging:
- step:
name: Build
caches:
- node
script:
- cd source
- npm install
- npm run build
artifacts:
- source/dist/**
- step:
name: Deploy
deployment: staging
script:
- pipe: atlassian/aws-s3-deploy:0.3.7
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: 'eu-west-1'
S3_BUCKET: 'company-vue-app-staging'
EXPIRES: '2030-01-01'
LOCAL_PATH: 'source/dist'
ACL: 'public-read'

On branch master the staging gets replaced with production.  Obviously having different conde on different branches is not good. 

So I tried using $BITBUCKET_DEPLOYMENT_ENVIRONMENT as per https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/ in step 2 for deployment with this:

- step:
name: Deploy
deployment: $BITBUCKET_DEPLOYMENT_ENVIRONMENT

However when I run the pipline for that deployment I get:

Configuration error

The environment '$BITBUCKET_DEPLOYMENT_ENVIRONMENT' in your bitbucket-pipelines.yml doesn’t match any environment defined in your settings. Either update your yml, or your settings, to use the same name.

This issue does seem to have been raised over 2 years ago: https://community.atlassian.com/t5/Bitbucket-questions/How-to-access-Bitbucket-Deployment-environment-name-from/qaq-p/750103

...but perhaps it is not the same cause as surely this would have been fixed by now?

 

I also looked at Deployment variables  - I set DEPLOYMENT_ENVIRONMENT in Repository Settings > Deployment UI, per deployment, along with this:

- step:
name: Deploy
deployment: $DEPLOYMENT_ENVIRONMENT

but again I get:

Configuration error

The environment '$DEPLOYMENT_ENVIRONMENT' in your bitbucket-pipelines.yml doesn’t match any environment defined in your settings. Either update your yml, or your settings, to use the same name.

I note on https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/ it says

"Deployment variables will only work within deployment steps in bitbucket-pipelines.yaml"

Any ideas what I am doing wrong here?

2 answers

1 accepted

0 votes
Answer accepted

I realised that I had missed the fact there is a "branches:" node under "pipelines:" so adding a "master:" at the same level as "staging:" means I can add my relevant "deployment:" staging/ production in there. i.e.

pipelines:
branches:
staging:
- step:
name: Deploy
deployment: staging
master:
- step:
name: Deploy
deployment: production

Hope that helps someone.

For anyone else in this situation - it seems it's not currently possible.  From Atlassian support:

I understand that you would like to use a variable for the deployment environment instead of hard-coded values in the yml. 

Unfortunately, this is not possible at the moment. The deployment environment name cannot be added as a variable. The Deployment Environment needs to be configured inside "Repo Settings > Pipelines > Deployments".

We do have a feature request for this requirement. You can track it at the below link:

Feature request: https://jira.atlassian.com/browse/BCLOUD-19611

I have linked your ticket internally to the feature request. Our development team will update the above ticket when there is any progress made. Hence I would suggest keeping a watch and vote for it. Do note however that there's no ETA on the feature request, and all enhancements are implemented with this policy in mind: https://confluence.atlassian.com/support/implementation-of-new-features-policy-201294576.html

Apologies for any inconvenience caused due to this.
 


So I tried using $BITBUCKET_DEPLOYMENT_ENVIRONMENT as per https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/ in step 2 for deployment with this:

With regards to the above, please note that BITBUCKET_DEPLOYMENT_ENVIRONMENT is a default(built-in) variable. It gives you the environment name inside a deployment section. You can use this variable to print the environment name inside the deployment steps. You cannot use it to set the deployment environment in yml. I hope it explains.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
Community showcase
Published in Bitbucket

Git push size limits are coming to Bitbucket Cloud starting April 4th, 2022

Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...

2,162 views 2 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you