The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to define variables at the pipeline or step level?

Götz
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!
December 19, 2023

Hi. In `bitbucket-pipelines.yml`  I'm trying to reduce duplication by reusing code using YAML anchors:

definitions:
deployment: &deployment
service:
- docker
script:
- |
echo "Debug"
docker version
echo "ENVIRONMENT: $ENVIRONMENT" # <-- here it fails as the variable is not defined.
# more steps, etc.

pipelines:
branches:
my_branch:
- step:
name: Deploy
image: docker:24
deployment: beta
variables:
ENVIRONMENT: beta
<<: *deployment

# There are more similar pipelines for different branches/tags using differnet variables.

This produces working YAML and passes the official validator, but it's not showing the `ENVIRONMENT` value, it acts as if the variable were empty.

What are the possible solutions to this? How to define variables at the pipeline level or at the step level?

Thanks.

 

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 21, 2023

Hello @Götz and welcome to the Community!

I' afraid the syntax you have used to define the variable at the step level is not currently supported, as Bitbucket Pipelines currently don't support step-specific variables.

We do have a feature request with our development team to implement this functionality: 

If you would be interested in that feature, we encourage you to add your Vote there as it helps our product managers to understand the demand. You can also mark yourself as a Watcher so you get notified of future updates on the development of that feature.

As an alternative, since your step is a deployment, you can create the variable as a Deployment variable, so you can have a variable with the same name but a different value in each deployment environment. 

Thank you, @Götz !

Patrik S

DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events