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:
- 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
name: Common Script Lines
- echo "hello world before from myCommonScriptLinesAnchor"
- echo "hello world after from myCommonScriptLinesAnchor"
The kind of resources I've come across:
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.
You can anchor a script the same way you anchor a step (I discovered this by accident -could not find any documentation for it):
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
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...
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