Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do manual build fail in Jenkins using shell script

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.

like image 825
Selvakumar Ponnusamy Avatar asked Dec 30 '13 18:12

Selvakumar Ponnusamy


People also ask

Why does Jenkins build fail?

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.

Can Jenkins run shell script?

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.

What happens if build fails in Jenkins?

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.

How do I fix Jenkins build failure?

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.


2 Answers

All you need to do is exit 1.

if [ -f "$file" ] then     echo "$file found." else     echo "$file not found."     exit 1 fi 
like image 149
alk3ovation Avatar answered Sep 23 '22 08:09

alk3ovation


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?.

like image 39
Ben Avatar answered Sep 20 '22 08:09

Ben