marvellous
marvellous

Reputation: 91

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 [email protected]:/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?

Upvotes: 0

Views: 1066

Answers (1)

Md Ayub Ali Sarker
Md Ayub Ali Sarker

Reputation: 11567

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 [email protected]:/home/deploy/app.zip using echo $?

Upvotes: 1

Related Questions