I'm trying to tidy up my pipeline file but I'm having trouble using a script when it has multiple lines.
Take this example which works fine:
image: xxxx
definitions:
# reusable scripts
scripts:
setQaEnvVariables: &setQaEnvVariables export USERNAME=$QA_USERNAME && export CONSUMERKEY=$QA_CONSUMER_KEY && export INSTANCEURL=$TEST_URL
validate: &validate if ! grep -q '<types>' package/package.xml && ! grep -q '<types>' destructiveChanges/destructiveChanges.xml; then echo "Packages are blank, there's no changes to validate"; exit 0; fi
# Reusable steps
steps:
- step: &validate-against-qa
name: Validate Against QA
script:
- *setQaEnvVariables
- *validate
pipelines:
custom: # Pipelines that can only be triggered manually
QA:
- step: *validate-against-qa
As soon as I try to use a multiline script block in validate, it throws compilation errors:
image: xxxx
definitions:
# reusable scripts
scripts:
setQaEnvVariables: &setQaEnvVariables export USERNAME=$QA_USERNAME && export CONSUMERKEY=$QA_CONSUMER_KEY && export INSTANCEURL=$TEST_URL
validate: &validate
- |
if ! grep -q '<types>' package/package.xml && ! grep -q '<types>' destructiveChanges/destructiveChanges.xml; then
echo "Packages are blank, there's no changes to validate"
exit 0
fi
# Reusable steps
steps:
- step: &validate-against-qa
name: Validate Against QA
script:
- *setQaEnvVariables
- *validate
pipelines:
custom: # Pipelines that can only be triggered manually
QA:
- step: *validate-against-qa
Its the same regardless of if I indent each line with its own - or use - |
If I use exactly the same script directly inside validate-against-qa it works just fine, so I can only conclude that there's some restriction I'm not aware of around multi line scripts. Is what I'm trying to do possible? I'd really like to be able to use several scripts that are multiple lines long!
Edit: pasting code into a code block in here takes away all my spacing and indentation, so I've had to do it manually. If you spot an indentation error it's likely not in my actual file