I was trying to run a jenkins Execute shell step with a grep to grep exceptions out of tomcat logs something like
echo "grepping logs for exceptions"
grep Exception purato.log*|grep -v WARN|grep -v DEBUG>error_summary.txt
problem was that if the log files had no exceptions then this step would fail and mark the job as failed. Now I wanted to mark the job as successful even though the grep didnt yeild any output. I tried various solutions from putting "exit 0" as last command but problem was jenkins would fail immediately first shell step it found failure.
Problem was jenkins starts shell with command
this -e means stop at first error.
adding "#!/bin/sh" at top of the shell solved the issue because now jenkins would respect this and wont start shell with -xe switch. Now it starts with
echo "grepping logs for exceptions"
grep Exception purato.log*|grep -v WARN|grep -v DEBUG>error_summary.txt
problem was that if the log files had no exceptions then this step would fail and mark the job as failed. Now I wanted to mark the job as successful even though the grep didnt yeild any output. I tried various solutions from putting "exit 0" as last command but problem was jenkins would fail immediately first shell step it found failure.
Problem was jenkins starts shell with command
[workspace] $ /bin/sh -xe /tmp/hudson6722324600236337826.sh
from man pages
"""
-e errexit If not interactive, exit immediately if any untested command fails.
The exit status of a command is considered to be explicitly tested
if the command is used to control an if, elif, while, or until; or if the command is the left hand operand of an “&&” or “||” operator.
"""
this -e means stop at first error.
adding "#!/bin/sh" at top of the shell solved the issue because now jenkins would respect this and wont start shell with -xe switch. Now it starts with
[workspace] $ /bin/sh /tmp/hudson342189479775158437.sh
Comments
Post a Comment