Hi, I’m trying to achieve similar effect from this question. My run
command looks like below:
COUNT=$(git diff --name-only HEAD HEAD~1 | grep ^mobile/ | wc -l | xargs )
echo 'Changed file count from mobile directory:'
echo $COUNT
if [ $COUNT == 0 ]; then
echo 'No change from mobile directory: end build'
curl --request POST \
--url https://circleci.com/api/v2/workflow/$CIRCLE_WORKFLOW_ID/cancel \
--header "Circle-Token: ${CIRCLE_TOKEN}"
exit 0
fi
While it does stop further running of workflow, the call of suggested API (or using circleci-agent step halt
) turns workflow status into ‘Failed’, not ‘Cancelled’, with output:
Exited with code exit status 1
CircleCI received exit code 1
I’d be much happier if there’s some way to make it ‘Cancelled’, so that I don’t have to manually check if ‘Failed’ build has actually failed due to a real problem, or it’s simply just skipped build.
Is there any way that I could cancel the workflow within itself, and make it ‘Cancelled’ status?