Can you help me see what's wrong with the command running under this step?

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
  image: alpine/git
  - change=$(git show $DRONE_COMMIT ./ 2> /dev/null); code=$?
  - if [ ! $code -eq 0 ]; then echo ' not fount.'; exit $code; fi
  - if [ -z $change ]; then echo ' 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 ./ 2> /dev/null); code=$?

Replaced with:

change=$(git show $DRONE_COMMIT ./ 2> /dev/null) || code=$?

Make it a complete command, so that solves the problem of non-zero return values!

1 Like