Do manual build fail in Jenkins using shell script Do manual build fail in Jenkins using shell script shell shell

Do manual build fail in Jenkins using shell script


All you need to do is exit 1.

if [ -f "$file" ]then    echo "$file found."else    echo "$file not found."    exit 1fi


To fail a Jenkins build from Windows PowerShell, you can use Steve's tip for C# as follows:

$theReturnCode = 1[System.Environment]::Exit( $theReturnCode )

Notes;

1.Windows recycles exit codes higher than 65535. ( https://stackoverflow.com/a/31881959/242110 )

2.The Jenkins REST API has a '/stop' command, but that will cancel the build instead of actually failing it. ( https://jenkinsapi.readthedocs.org/en/latest/build.html )

3.Jenkins can also mark a build 'unstable', and this post ( https://stackoverflow.com/a/8822743/242110 ) has details on that solution.