Skip to content

CI Handle Circle CI REST API response #25340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions build_tools/github/trigger_hosting.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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