How can I get a job to fail when a regex does not matches the output?

474 views
Skip to first unread message

Sahil Minocha

unread,
Oct 16, 2014, 7:50:24 AM10/16/14
to jenkins...@googlegroups.com
Hi,

I am using Conditional Steps(Multiple) and Steps to run if condition is met.
I have a scenario to fail the build if an expression is not found in the Console Output.
What I am able to achieve is, I can change the build output when an expression matches using Text FInder, however I need to do the vice-a-versa.
I need to abort/fail the build if the regex does not matches the output.

For example, if the condition is not met, Jenkins says:
Checking console output
Run condition [Text Finder] preventing perform for step [BuilderChain]
Finished: SUCCESS

Whereas, if this "Run condition [Text Finder] preventing perform for step [BuilderChain]" arrives, I need to abort/fail the  build.

Any help would be appreciated.

Thanks in advance,
Sahil.

Maciej Jaros

unread,
Oct 27, 2014, 6:13:00 AM10/27/14
to jenkins...@googlegroups.com
Sahil Minocha (2014-10-16 13:50):
Hi,

I am using Conditional Steps(Multiple) and Steps to run if condition is met.
I have a scenario to fail the build if an expression is not found in the Console Output.
What I am able to achieve is, I can change the build output when an expression matches using Text FInder, however I need to do the vice-a-versa.
I need to abort/fail the build if the regex does not matches the output.

You can create a file if the condition was met (e.g. file "condition_x_matched"). Then add a Execute shell step and chaeck for the existance of the file. If the file does not exist - fail the build e.g. by doing `exit 1`.

Regards,
Nux

Sahil Minocha

unread,
Nov 3, 2014, 4:40:46 AM11/3/14
to jenkins...@googlegroups.com
Hi Nux,

Thanks for the reply. This logic worked for me.
Though I might not rely on Files/IO for the job output, however I have used the same approach with System variables and worked fine for me.
For best output, I would still be seeking if there is any plugin which permits the else condition as well.
Regards,
Sahil

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/VZ6eKEMU1W4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages