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

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
Accepted answer

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.

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.

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).

Thanks for the suggestions Piotr.

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
Community showcase
Posted Monday in Confluence

Organizing your space just got easier - Page Tree Drag & Drop is here

Hi Community! I’m Elaine, Confluence Product Manager. You may have read my earlier post about page tree in space navigation sidebar. I'm excited to share another improvement that helps you organize ...

68 views 3 2
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you