Unable to load variables for multiple YAML anchors

Younusuddin Mohammad
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!
March 4, 2025

Hi Team, 

I am trying to reduce reusable code within my project pipeline; however, I am facing issues while passing a variable to the pipeline.

definitions:
  steps:
     - step: &reusable-deploy-step
          name: "deploy"
          script:
             - echo "Deploying in $Environment"
pipelines:
   custom:
       deploy-all-sandboxes:
          parallel:
              - step:
                    <<: *reusable-deploy-step
                     name: "deploy to Dev sandbox"
                     variables:
                         Environment: "Dev"
              -step:
                   <<: *reusable-deploy-step
                    name: "Deploy to QA sandbox"
                    variables:
                         Environment: "QA"

I am encountering an issue where the YAML validates in Bitbucket validator passes successfully. However, when running the pipeline, the environment variable value appears empty.

Can someone provide any suggestions to resolve this?

 

 

 

 

1 answer

0 votes
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 5, 2025

Hi @Younusuddin Mohammad and welcome to the community!

There is a bug with the validator and when yaml anchors are used, the validator does't show errors. The reason that the variables in your builds are empty is that the keyword variables cannot be used this way in a custom pipeline, it can only be used in the way described in this doc.

What you can do is set up deployment environments in this repository, define variables in these environments, and then adjust your yml. You need to have admin permissions to the repo to set up deployment environments.

These are the steps to do this:

  1. Open the repository on Bitbucket's website.

  2. Select Repository settings from the left sidebar.

  3. Select Environments from the new left sidebar.

    In there, you can rename the existing default environments or add new ones.

    Please keep in mind that since you want to use these in parallel steps, the two deployment environments should be of the same type. I.e. they should both be under Test environments, or under Staging environments, or under Production environments.

  4. For each environment that you have added and want to use:

    • Expand it, and you will see an option to add variables to this environment.

      You can add a variable to each environment with the same name (e.g. Environment) and different value.

  5. You can then adjust your yml file as follows:

    (Dev and QA should be the names you have set for the deployment environments in Step 3)

    definitions:
    steps:
    - step: &reusable-deploy-step
    name: "deploy"
    script:
    - echo "Deploying in $Environment"

    pipelines:
    custom:
    deploy-all-sandboxes:
    - parallel:
    - step:
    <<: *reusable-deploy-step
    name: "Deploy to Dev sandbox"
    deployment: Dev
    - step:
    <<: *reusable-deploy-step
    name: "Deploy to QA sandbox"
    deployment: QA

Please feel free to reach out if you have any questions!

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events