tags:

views:

22

answers:

1

My build and deploy step creates some logs. I would like to search the logs for and fail the build if I see certain strings.

A good log looks like

log stuff
step 1: SUCCESS
step 2: SUCCESS

A log with failures would look like

log stuff
step 1: SUCCESS
step 2: FAIL

My check is

grep FAIL /path/to/build.log
if [ $? -eq 0 ]; then
  exit 1
fi

I've also tried

RESULT=`grep FAIL /path/to/build.log`
if [ -n "$RESULT" ]; then
  exit 1
fi

and various ways of piping in the file.

Hudson is failing the build on grep not returning anything. So is there a better way to search for the string? Is there a way to have grep not returning anything not exit the script right there?

Version Stuff: * Hudson 1.355

+2  A: 

From the hudson documentation for a shell command:

By default, the shell will be invoked with the "-ex" option. So all of the commands are printed before being executed, and the build is considered a failure if any of the commands exits with a non-zero exit code. Again, add the #!/bin/... line to change this behavior.

So, try adding a #!/bin/sh line and see what it does?

wds
I'm glad you posted this. I have been using a really yucky workaround for this problem. I'm going to give this a try.
Jack Leow