jeudi 27 juillet 2017

Shell Script won't fail in Jenkins

I have a simple shell script which I want to set up as a periodic Jenkins job rather than a cronjob for visibility and usability for less experienced users.

Here is the script:

#!/bin/bash
outputfile=/opt/jhc/streaming/check_error_output.txt

if [ "grep -sq 'Unable' $outputfile" == "0" ]; then
    echo -e "ERROR MESSAGE FOUND\n"
    exit 1
else
    echo -e "NO ERROR MESSAGES HAVE BEEN FOUND\n"
    exit 0
fi

My script will always return "NO ERROR MESSAGES HAVE BEEN FOUND" regardless of whether or not 'Unable' is in $outputfile, what am I doing wrong?

I also need my Jenkins job to class this as a success if 'Unable' isn't found (e.g. If script returns "0" then pass, everything else is fail)

Aucun commentaire:

Enregistrer un commentaire