Reputation: 95
I'm tring the following at Jenkins in aim to search strings of failures in jobs.
This will run on daily basis.
def sd = "2020" + "${env.START_DATE}" + "0000"
def ed = "2020" + "${env.END_DATE}" + "2359.59"
pipeline {
agent {label "master"}
stages {
stage('Build') {
steps {
print(sd)
sh 'echo "Hello World"'
sh """
pwd
#rm end-time start-time
#rm $WORKSPACE/$PARSING_OUTPUT
touch -t $sd $WORKSPACE/start-time
touch -t $ed $WORKSPACE/end-time
find /var/lib/jenkins/jobs/. -type f -newer $WORKSPACE/start-time ! -newer $WORKSPACE/end-time -name '*' -exec grep $SEARCH_STRING /dev/null {} + >> $WORKSPACE/$PARSING_OUTPUT
ls -ltr
"""
}
post {
always {
echo "sending mail"
//mail to: '[email protected]',
//subject: "Parse Jenkins log",
//body: "TBD"
//body: "${env.BUILD_URL} has result ${currentBuild.result}"
}
}
}
}
}
My problem is that if the string I'm looking for isn't exsist. the job fail..
Console output display ERROR: script returned exit code 1
.
I tried adding #!/bin/sh
that will allow me to execute with no option - didn't help.
any suggestions ?
Upvotes: 3
Views: 15432
Reputation: 677
There are multiple way to achive above
use set +e
# Disable exit on non-zero
sh ''''
set +e
..
'''
use OR || with cmd
sh''''
$CMD || echo "string doesn't exist."
'''
use like below
sh (
script: 'YOUR SCRIPT',
returnStatus: true
)
Upvotes: 8