Workaround for "when" Attribute
While CircleCI Server does not currently support the when attribute for a run step, the following will allow a build to execute a different series of commands when a command fails:
- run: | # Disable fail on error set +eo pipefail echo "Run commands here" if [ $? -ne 0 ]; then echo "Steps for error" # Return either exit 1 or exit 0 # depending on if you want the step # to be success or failure exit 0 fi # Re-enable fail on error set -eo pipefail echo "Other steps if does not fail"
Be sure to set
-eo pipeline after the
if statement. If we do not re-enable it after the if statement, any additional errors will still produce a success(green) build.
If we want the failed command to still have a failed(red) status, we would return
exit 1 instead of