This is pretty bizarre.
I opened file .gitlab-ci.yml
in Gitlab's Pipeline Editor.
When I have double-quoted string without spaces in the file it's OK:
Note no space between PRIVATE-TOKEN:
and $EXAMPLE_TOKEN
.
Pipeline Editor says " Pipeline syntax is correct." and all is fine, I can run the pipeline on commit etc.
However, when I enter a space there the editor complains:
At the top the editor displays message:
"This GitLab CI configuration is invalid: jobs:build_appliance:after_script config should be a string or a nested array of strings up to 10 levels deep."
Trying to run the pipeline on commit fails with messages about invalid YAML. The strange thing is I checked this string in an online YAML validator and it says it's fine.
This is a common issue even I face when I use curl with "--
" options. The Gitlab yaml parser gets thrown off by this "--
".
Here is how you can work around this. Please note the "|
" at the begining of your after_script
, with which you can avoid both adding a "-" on each line of your script and also this solves the nested string error message.
You can use "|" similarly in before_script
and script
as well.
sample after script with dummy echo just to show mutiple lines of script
after_script: |
echo "I dont have to use "-" on each line os script section anymore"
curl --globoff --header "PRIVATE-TOKEN: <your_access_token>" "<your gitlab api url>"
echo "more lines..."