How do I fail the build if certain string appears in log

Charles November 29, 2011

I have a script task in one of my jobs that calls a command which doesn't return a proper error code when it fails. It does, however, log a message in the logs indicating the failure. What I'd like to do is define some keywords (regular expressions) that bamboo searches for in the build logs and fails the build if any are found.

I've had a look, but can't seem to find any features like this in Bamboo. Is it possible?

3 answers

1 accepted

1 vote
Answer accepted
Przemek Bruski
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 29, 2011

If you are using Linux, maybe you could enhance your script task - redirect your output to a file, grep it, cat it and return a result.

Another option would be to create a wrapper command that will return a proper exit code.

Finally. you could write a simple Bamboo task that launches your command (it's really easy!). Tasks writing tutorial.

If you decide to write a task, look at StringMatchingInterceptor and its usages to see how to match a string against log lines.

Charles December 4, 2011

Thanks for the suggestions. I ended up tee'ing the output to a file and using the return code of grep to deteremine success/failure.

1 vote
PiotrA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 29, 2011

Not out of the box. I've heard there are people with similar requirements and from what I recall they end writing up their own plugins. And in your situation (fail build when log message is encountered) I'd go the same way, by writing custom plugin.

I'd write postBuildAction plugin which would scan buildLogs for particular string after each job is completed - I'd base on http://confluence.atlassian.com/display/BAMBOO030/Tutorial+1+-+Getting+Started+with+a+Simple+Post+Build+Labeller .The "Simple Post Build Labeller" has similar functionality, it just labels the builds instead of failing them.

Not very easy solution, but doable if you have programming skills (and time).

Charles December 4, 2011

Thanks for the suggestions Piotr.

0 votes
Charles December 4, 2011

Thanks for the suggestions guys. I ended up tee'ing the output to a file and using the return code of grep to deteremine success/failure.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events