Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

Multiple anchors in a step (each anchor is a script)

I am trying to reduce the amount of duplicated code in my .yml file. I've defined scripts at the top, then I try to reuse them in the different pipelines. I checked the syntax using the Bitbucket syntax validator and it was correct. The pipelines, however, do not build. I get the following error:

"There is an error in your bitbucket-pipelines.yml at 
[pipelines > default > 0 > step > script].
To be precise: This section should be a list (it is currently defined as a map)."

 Here's what I've been trying:

 

image: atlassian/default-image:2

options:
size: 2x

definitions:
  scripts:
    script_dependencies: &install_dependencies
      - my steps

  script_regular: &build_regular
    - some more steps

  script_release_candidate: &build_release_candidate
    - some more steps

pipelines:
  default:
    - step:
        script:
          script_dependencies: *install_dependencies
          script_regular: *build_regular

  custom:
    manual_run_release_candidate:
      - step:
          script:
            script_dependencies: *install_dependencies
            script_release_candidate: *build_release_candidate

 

Is there something wrong with this? Would appreciate some insight. Thank you.

1 answer

0 votes

Hi @Raiyan Ishmam,

As far as I know, the sections represented by anchors cannot be merged. They can be updated with <<: but not merged. It means that you can only reference one script section per step, not two of them in the same step/script.

You don't see any YML validation error due to the problem reported here:

I was checking a way to rewrite your script and this was my solution:


image: atlassian/default-image:2

options:
  size: 2x

definitions:
   script_dependencies: &install_dependencies
        - echo "install_dependencies"

  
script_regular: &build_regular
        - echo "build_regular"

   script_release_candidate: &build_release_candidate
        - echo "build_release_candidate"

pipelines:
  default:
    - step:
        script: *install_dependencies
    - step:
        script: *build_regular

  custom:
    manual_run_release_candidate:
      - step:
          script: *install_dependencies
      - step:
          script: *build_release_candidate

I hope that helps.

Sorry for awakening this topic, but I have a similar issue but cannot use your suggested rewrite. My `*install_dependencies`-equivalent depends on deployment environment variables, which is only available in the last step. Any clean way around this? 

It seems that the lack of merging lists in yaml and the lack of using environment variables outside of the deployment step, keeps getting in my way of defining a clean, easy to understand, build script. They end up having messy, duplicated sections due to these shortcomings. Which is unfortunate, because it seems like these capabilities shouldn't be too difficult to implement. :/ 

Suggest an answer

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

New improvements to user management in Bitbucket Cloud 👥

Hey Community! We’re willing to wager that quite a few of you not only use Bitbucket, but administer it too. Our team is excited to share that we’ll be releasing improvements throughout this month of...

3,888 views 10 16
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