Prevent silent failure of scheduled cleanup & fix cleanup for API with authentication
What does this MR do and why?
On Orange side some Sylva pipelined are reused, and we noticed a bug when CAPO_CLEANUP_GITLAB_AUTH_TOKEN is set. The bash substitution done in the curl command is not correctly interpreted by the curl command; --header PRIVATE-TOKEN: xxxxx is seen as a curl option and not an option + values
eg of failure:
curl -f ${CAPO_CLEANUP_GITLAB_AUTH_TOKEN:+--header \"PRIVATE-TOKEN: $CAPO_CLEANUP_GITLAB_AUTH_TOKEN\"} https://gitlab.xxxx/api/v4/projects/xxxxx/pipelines/xxxxxx
curl: option --header "PRIVATE-TOKEN: xxxxxxxx": is unknown
curl: try 'curl --help' or 'curl --manual' for more information
This MR fix it by using a different command in each case.
Also it prevent silent failure, as before we use:
if curl -s -f ${CAPO_CLEANUP_GITLAB_AUTH_TOKEN:+--header \"PRIVATE-TOKEN: $CAPO_CLEANUP_GITLAB_AUTH_TOKEN\"} ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/pipelines/${STACK_PIPELINE_ID} | jq -e '.status != "running"';
in case of curl failure, the script wasn't failing and the error was hidden by the if statement and lead to have the given pipeline put in exclude-tags.
Separating the commands allow to exit in error if the curl command fail.
Tested here: https://gitlab.com/sylva-projects/sylva-core/-/jobs/8173274520
Edited by Loic Nicolle