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

Your Points Tracker
  • 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
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?
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

Pipelines Anchors/Aliases for Script Command Snippets

I've seen answers for reusing steps, but are there any for certain script commands to run?

I'm looking to do something along the lines of this:

commonScriptLinesAnchor: &myCommonScriptLinesAnchor
- echo "hello world from myCommonScriptLinesAnchor"
- echo "hello world again from myCommonScriptLinesAnchor"


custom: # Pipelines that are triggered manually via the Bitbucket GUI

anchor-test: # Use anchors and references in various ways
- step:
name: Common Script Lines
- echo "hello world before from myCommonScriptLinesAnchor"
- echo "hello world after from myCommonScriptLinesAnchor"


The kind of resources I've come across:



2 answers

1 accepted

4 votes
Answer accepted

Hi Joshua,

I'm not sure if you can interleave anchors and other items into the YAML like that.

If you remove the hello world before and after your myCommonScriptLinesAnchor then it will work fine.

As far as I can find, there isn't a way to merge arrays in YAML using anchors.

All the things I tried also had a similar result where it was a list of list of commands, rather than a list of commands. Which our parser doesn't support.

Instead you could try use a script file to pull out common functionality between pipeline definitions.



You can anchor a script the same way you anchor a step (I discovered this by accident -could not find any documentation for it):

script: &My-Script-A
- ...
script: &My-Script-B
- ...
- step:
script: *My-Script-A
script: *My-Script-B

Full disclose, the above used to work just fine until a couple of days ago. For some reason when multiple scripts are referenced (like above) only the last one (My-Script-B) gets executed. See related post:

This doesn't work, because the step value is a mapping, and keys are unique. The second `script` key replaced the first, which is why only the last one is being executed.

Like Khalifa EL BANAN likes this

Suggest an answer

Log in or Sign up to answer
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...

514 views 6 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