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

Your Points Tracker
Challenges
Leaderboard
  • 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
Recognition
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?
Kudos
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"

pipelines:

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

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

 

The kind of resources I've come across:

https://community.atlassian.com/t5/Bitbucket-questions/How-to-reuse-steps-for-different-branches/qaq-p/875615

https://confluence.atlassian.com/bitbucket/yaml-anchors-960154027.html

 

Thanks!

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. https://stackoverflow.com/questions/24090177/how-to-merge-yaml-arrays/30770740#30770740

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.

Thanks,

Phil

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

definitions: 
script: &My-Script-A
- ...
script: &My-Script-B
- ...
pipelines:
custom:
my-custom-pipeline:
- 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: https://community.atlassian.com/t5/Bitbucket-questions/Pipeline-with-multiple-scripts-runs-only-the-last-one-broken-bug/qaq-p/1239759#M49684

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
TAGS
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