diff --git a/build_tools/github/trigger_hosting.sh b/build_tools/github/trigger_hosting.sh index 2a8e28ff164ff..e05b03366d868 100755 --- a/build_tools/github/trigger_hosting.sh +++ b/build_tools/github/trigger_hosting.sh @@ -31,10 +31,32 @@ else BRANCH=$HEAD_BRANCH fi -curl --request POST \ +# Circle CI REST API returns HTTP responses with 20x status code even when the POST requests fail. +# Hence we add some handling so that errors are reported on GitHub. +# For details see: https://circleci.com/docs/api/v2/index.html#operation/triggerPipeline +CIRCLE_CI_RESPONSE=$(curl --request POST \ --url https://circleci.com/api/v2/project/gh/$GITHUB_REPOSITORY/pipeline \ --header "Circle-Token: $CIRCLE_CI_TOKEN" \ --header "content-type: application/json" \ --header "x-attribution-actor-id: github_actions" \ --header "x-attribution-login: github_actions" \ - --data \{\"branch\":\"$BRANCH\",\"parameters\":\{\"GITHUB_RUN_URL\":\"$GITHUB_RUN_URL\"\}\} + --data \{\"branch\":\"$BRANCH\",\"parameters\":\{\"GITHUB_RUN_URL\":\"$GITHUB_RUN_URL\"\}\}) + + +CIRCLE_CI_RESPONSE_MESSAGE=$(echo $CIRCLE_CI_RESPONSE | jq ".message") + +if [[ "$CIRCLE_CI_RESPONSE_MESSAGE" == "null" ]]; then + exit 0 # No message means there was no error. +fi + +if [[ "$CIRCLE_CI_RESPONSE_MESSAGE" =~ .*"Not Found".* ]]; then + echo "The endpoint has not been found on Circle CI REST API. Please check the request correctness." +fi + +if [[ "$CIRCLE_CI_RESPONSE_MESSAGE" =~ .*"Permission denied".* ]]; then + echo "Circle CI is blocking the start of the pipeline." + echo "Please check for correct registration of tokens on Circle CI on: https://app.circleci.com/settings/user/tokens" + echo "See: https://support.circleci.com/hc/en-us/articles/360050351292-How-to-Trigger-a-Workflow-via-CircleCI-API-v2" +fi + +exit 1