简体   繁体   中英

Jenkins build is not marked as failed if there is an error during .sh file execution

The Jenkins job contains Execute shell step with the following command:

scp file.zip deploy@host.name:/home/deploy/app.zip

If 'file.zip' does not exist the build obviously fails.

Then I create shell script file with the same command, say deploy.sh, and change Execute shell command in Jenkins to:

./deploy.sh

In this case if 'file.zip' does not exist Console Output contains error message, but the build is marked as successful.

What should I do to have build marked as failed in this case as well?

By default Jenkins take /bin/sh -xe and -x will print each and every command.And the other option -e, which causes shell to stop running a script immediately when any command exits with non-zero (when any command fails) exit code.

So by adding the #!/bin/sh will allow you to execute with no option.

you have to know which code it is returning after executing scp file.zip deploy@host.name:/home/deploy/app.zip using echo $?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM