I would like to mark a Jenkins build to fail on one scenario for example:
if [ -f "$file" ] then echo "$file found." else echo "$file not found." #Do Jenkins Build Fail fi
Is it possible via Shell Script?
Answer: If we exit with integer 1, Jenkins build will be marked as failed. So I replaced the comment with exit 1
to resolve this.
In Jenkins, in the pipeline where failure occurred, in the pane, select the latest build, and click Console Output. On the Console Output page, check the logs to find the reason for the failure. If required, update the parameters in the deployment input configuration file.
These are the steps to execute a shell script in Jenkins: In the main page of Jenkins select New Item. Enter an item name like "my shell script job" and chose Freestyle project. Press OK.
The Build Failure Analyzer Jenkins plugin analyzes the causes of failed builds and presents the causes on the build page. It does this by using a knowledge base of build failure causes maintained from scratch.
Open the log files one by one and go to the end of file(ctrl+end). Error details will be displayed, if the error has occured in that file. Fix the ERRORs in the local setup first & then do the checkins to the repository again.
All you need to do is exit 1.
if [ -f "$file" ] then echo "$file found." else echo "$file not found." exit 1 fi
To fail a Jenkins build from .NET, you can use Environment.Exit(1)
.
Also, see How do I specify the exit code of a console application in .NET?.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With