Reputation: 127
The end goal is to search for all the files n sub-directories within a folder a on a Linux box for control m characters. If yes, do not proceed with the ANT build and fail the job. If not, proceed with the ANT build.
In a Jenkins job I write this script outline of the script
:
Cd batch Grep -r "\r" > text-file \ to find ctrl m char and redirect to text file if so.
Then compare the content. If text file is empty build else fail the job.
If [-s] fail job else build.
Is this a good approach of using Linux script to achieve? If not what's the better way?
How to configure a Jenkins job using execute shell and to make the shell fail and the Jenkins job fail on condition ?
Thanks
Upvotes: 3
Views: 9835
Reputation: 4654
For those who still find it difficult to understand how and where to write exit with non-zero value. Below is a Jenkins pipeline script with a non-zero exit.
pipeline{
agent any
stages{
stage('Git Checkout'){
steps{
git branch: "${BRANCH}",
credentialsId: 'github-cred',
url: 'https://github.com/exam105/some-repo.git'
exit 1
}
}
stage('Build Project'){
steps{
}
}
}
}
The Build Project stage will not run.
Upvotes: 1
Reputation: 18459
Option 1: Exit your scripts with non zero value. Jenkins, by default, detect this as failure.
Option 2: Use Console Parser plugin for looking for error patterns.
Both can be combined with Build failure analyser for neat message to user.
Upvotes: 3