Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
Level
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

How to access Bitbucket Deployment environment name from Pipeline step script? Edited

Hello,

Environment variables available from pipeline steps are listed here: 

https://confluence.atlassian.com/bitbucket/environment-variables-794502608.html

There doesn't seem to be a way to find out which deployment environment is set for this step at the moment (i.e. via fictional BITBUCKET_DEPLOYMENT variable). This is needed for deployment script to decide what to do, otherwise, steps can't be reused for different environments.

Am I missing something?

Many thanks!

2 answers

1 accepted

0 votes
Answer accepted

Hi Yury,

Currently there's no BITBUCKET_DEPLOYMENT type environment variable.

Is there any reason that you cannot hard code this inside you're step scripts, given that you already need to specify the environment name on the step?

For example:

pipelines:
default:
- step:
name: Deploy to test
deployment: test
script:
- export DEPLOYMENT_NAME=test
- ./deploy-to-env
- step:
name: Deploy to staging
deployment: staging
script:
- export DEPLOYMENT_NAME=staging
- ./deploy-to-env

Does that suit you, or did you have some different use cases?

You can also open a feature request for such an environment variable here: https://bitbucket.org/site/master/issues?status=new&status=open&component=Pipelines

Thanks,

Phil

Hi Philip,

Of course, I can hardcode the environment in the deployment script in addition to specifying it in step itself. My question was, however, how can I avoid precisely that.

There are several reasons as to why I would like to avoid it if at all possible.

  1. It causes annoying duplication of code because once I hardcode it into the scripts, I cannot reuse them between steps anymore, because it is not possible in YAML to merge lists, only dicts.
  2. Once you start duplicating code, the deployment environment in step and in the script can very quickly fall out of sync, which in turn can lead to real badness like deploying to the wrong environment.

An obvious way would be to find out which deployment environment is active by querying an environment variable, but very unfortunately you confirmed that it is not available.

I have created a new feature request as instructed:

https://bitbucket.org/site/master/issues/15987/make-step-deployment-accessible-as

--Yury

Like Ronan Pereira likes this

Hi Yury,

You should be able accomplish this now using deployment environment variables defined under the pipelines -> deployments settings screen.

I'm in need of accessing the name of the deployment environment inside the steps with reusable scripts.

Right now, I'm thinking to go ahead with explicitly mentioning/adding one more environment variable called 'BITBUCKET_DEPLOYMENT' under each deployment and repeating the deployment name itself there.

It would be nice to see this feature included as part of Bitbucket itself. thanks.

Hello,

We’ve added the following default variables to Pipelines:

  • BITBUCKET_DEPLOYMENT_ENVIRONMENT - The URL friendly version of the environment name.
  • BITBUCKET_DEPLOYMENT_ENVIRONMENT_UUID - The UUID of the environment to access environments via the REST API.

These are also documented with our other variables.

Thanks,
Phil

Like # people like this

These variables (BITBUCKET_DEPLOYMENT_ENVIRONMENT_UUID and BITBUCKET_DEPLOYMENT_ENVIRONMENT) are neither set nor documented, in the 2020th foul year of Our Lord.

Like # people like this

After almost three years of struggling, we've solved our problems with Bitbucket by migrating to GitHub, and it's got cheaper on top of that.

Like # people like this

@Philip Hodderwhat's the deal? These are not documented.

Like Sander Mol likes this

What's the latest on this @Philip Hodder - These environment variables still do not appear to being set.  Can you advise ASAP?

Like Tobias Schäfer likes this

Hello,

I still get an issue 'variable missing' although used deployment pipelines setting

 This is my yaml

pipelines:  branches:    develop:      - step:          name: Build          script:            - zip -r myapp.zip *          artifacts:            - myapp.zip      - step:          name: Upload to S3          services:            - docker          script:            - pipe: atlassian/aws-code-deploy:0.3.2              variables:                BITBUCKET_DEPLOYMENT_ENVIRONMENT: 'staging'                AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID                AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY                AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION                S3_BUCKET: $S3_BUCKET                COMMAND: 'upload'                APPLICATION_NAME: $APPLICATION_NAME                ZIP_FILE: 'myapp.zip'

 Please help!

Thank you

Suggest an answer

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

Calling any interview participants for Bitbucket Data Center

Hi everyone,  We are looking to learn more about development teams’ workflows and pain points, especially around DevOps, integrations, administration, scale, security, and the related challeng...

477 views 5 4
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