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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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
Posted in Bitbucket

How do you use the Bitbucket-Jira integration? How does it help your team?

Hey everyone, over the past year, we've added several new features on how you can use Bitbucket and Jira together. We'd love to know how you'll are using the integration and how it's helping your t...

120 views 0 2
Join discussion

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