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://confluence.atlassian.com/bitbucket/yaml-anchors-960154027.html
Thanks!
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.