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?