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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.