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 votes

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 Join to answer
Community showcase
Renan Battaglin
Published May 18, 2017 in Bamboo

FAQ: How to Upgrade Bamboo Server

Bamboo 5.9 will no longer be supported after June 12, 2017. What does this mean? As part of our End of Life policy, Atlassian supports major versions for two years after the first major iteratio...

1,070 views 0 5
Read article

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot