In order to prevent the step from failing after receiving a non-zero return code, I used code = $? To receive the error code so that this command that might fail returns 0, but it seems that this still does not solve the problem of step failure .
- name: lint
- change=$(git show $DRONE_COMMIT ./CHANGELOG.md 2> /dev/null); code=$?
- if [ ! $code -eq 0 ]; then echo 'CHANGELOG.md not fount.'; exit $code; fi
- if [ -z $change ]; then echo 'CHANGELOG.md no change.'; exit 1; fi
I solved it myself!
I suspect that drone’s step operation mechanism is separated by
;. Even if it is written on a line, it will check the return value of each paragraph one by one. Once a non-zero return occurs, it is determined that the execution has failed.
So I just put:
change=$(git show $DRONE_COMMIT ./CHANGELOG.md 2> /dev/null); code=$?
change=$(git show $DRONE_COMMIT ./CHANGELOG.md 2> /dev/null) || code=$?
Make it a complete command, so that solves the problem of non-zero return values!