Conditional Step Regular Expression Match

871 views
Skip to first unread message

Eric Fetzer

unread,
Feb 29, 2016, 4:32:08 PM2/29/16
to Jenkins Users
I don't understand why the following is a match for my regex.  Can someone tell me what makes it a match?

Regular expression run condition: Expression=[.*(OIS-Reports|OIS-ALL)*], Label=[OIS-Client,OIS-Server]
Run condition [Regular expression match] enabling perform for step [Trigger/call builds on other projects]

Thanks,
Eric

Eric Pyle

unread,
Feb 29, 2016, 4:48:51 PM2/29/16
to jenkins...@googlegroups.com
Off the top of my head, the square brackets "[" and "]" are meaningful in RE syntax, representing a character class. Have you tried escaping them?
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/0043b1a8-3d52-48b1-8009-074e66734783%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Eric Fetzer

unread,
Mar 1, 2016, 9:20:51 AM3/1/16
to Jenkins Users
Thanks for the reply Eric!  Sorry, the square brackets are just from the Jenkins output.  My regex's look like this (4 single conditional steps based on the label passed in build.apps):

.*(NAP-Client|NAP-ALL)*
.*(NAP-Server|NAP-ALL)*
.*(NAP-Reports|NAP-ALL)*
.*(CAS|NAP-ALL)*

In this particular case, I passed in build.apps='NAP-Client,NAP-Server'

So it should go in and trigger the build associated with these two regex's.  But what it does is go into all 4 and build them.  I'm guessing I could put anything at all in the Label and it would match for all of these conditions because of a mistake I'm making in my regex.

Thanks,
Eric

Matthew...@diamond.ac.uk

unread,
Mar 1, 2016, 10:06:10 AM3/1/16
to jenkins...@googlegroups.com

A regex that starts with .* and ends with (opt1|opt2)* will always match all strings.

I think you want something like .*( opt1|opt2)+ where the trailing + means at least one thing from opt1|opt2 must be present.

--

You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.

 

-- 

This e-mail and any attachments may contain confidential, copyright and or privileged material, and are for the use of the intended addressee only. If you are not the intended addressee or an authorised recipient of the addressee please notify us of receipt by returning the e-mail and do not use, copy, retain, distribute or disclose the information in or attached to the e-mail.
Any opinions expressed within this e-mail are those of the individual and not necessarily of Diamond Light Source Ltd.
Diamond Light Source Ltd. cannot guarantee that this e-mail or any attachments are free from viruses and we cannot accept liability for any damage which you may sustain as a result of software viruses which may be transmitted in or with the message.
Diamond Light Source Limited (company no. 4375679). Registered in England and Wales with its registered office at Diamond House, Harwell Science and Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom
 

Eric Fetzer

unread,
Mar 1, 2016, 11:14:07 AM3/1/16
to Jenkins Users
Thanks for your response Matthew!  With your change, we seem to be a lot closer.  I have from 1 to 4 conditional projects to call.  In this particular build, I'm telling it to do 2 of the 4.  Here's what it did based on the condition:

Regular expression run condition: Expression=[.*(NAP-Client|NAP-ALL)+], Label=[NAP-Client,NAP-Server]
Run condition [Regular expression match] preventing perform for step [Trigger/call builds on other projects]       Didn't go into this one which it should have
Regular expression run condition: Expression=[.*(NAP-Server|NAP-ALL)+], Label=[NAP-Client,NAP-Server]     Went into this one as it should have

Run condition [Regular expression match] enabling perform for step [Trigger/call builds on other projects]
Returning node parameter for master
Waiting for the completion of NAP-Server
NAP-Server #98 completed. Result was SUCCESS
Regular expression run condition: Expression=[.*(NAP-Reports|NAP-ALL)+], Label=[NAP-Client,NAP-Server]    Didn't go in as it shouldn't have
Run condition [Regular expression match] preventing perform for step [Trigger/call builds on other projects]    
Regular expression run condition: Expression=[.*(CAS|NAP-ALL)+], Label=[NAP-Client,NAP-Server]     Didn't go in as it shouldn't have
Run condition [Regular expression match] preventing perform for step [Trigger/call builds on other projects]
Warning: you have no plugins providing access control for builds, so falling back to legacy behavior of permitting any downstream builds to be triggered

Is it having a problem with the ".*" because NAP-Client occurs at the beginning of the line?



On Monday, February 29, 2016 at 2:32:08 PM UTC-7, Eric Fetzer wrote:

Matthew...@diamond.ac.uk

unread,
Mar 1, 2016, 11:51:00 AM3/1/16
to jenkins...@googlegroups.com

As far as I can see, the “Label” is just a string. So Label=[NAP-Client,NAP-Server] does not try comparing 2 different string with the regex, it’s simply a single string that happebns to have a comma in the middle of it. That comma does not means anything special, because this is not a regex.

 

So, the first Expression=[.*(NAP-Client|NAP-ALL)+], Label=[NAP-Client,NAP-Server] example, which you say gives the wrong result:

The regex will match something that ENDS with either NAP-Client or NAP-ALL. The label does not match that.

I think what you want is .*(NAP-Client|NAP-ALL).* which matches either NAP-Client or NAP-ALL, surrounded by anything (or nothing).

This is similar to what you first had, except that it ends with “.*” rather than “*”.

 

Hope that helps and that I’ve understood correctly what’s going on.

 

Matthew Webber

 

From: jenkins...@googlegroups.com [mailto:jenkins...@googlegroups.com] On Behalf Of Eric Fetzer
Sent: 01 March 2016 16:14
To: Jenkins Users
Subject: Re: Conditional Step Regular Expression Match

 

Thanks for your response Matthew!  With your change, we seem to be a lot closer.  I have from 1 to 4 conditional projects to call.  In this particular build, I'm telling it to do 2 of the 4.  Here's what it did based on the condition:

 

Regular expression run condition: Expression=[.*(NAP-Client|NAP-ALL)+], Label=[NAP-Client,NAP-Server]
Run condition [Regular expression match] preventing perform for step [Trigger/call builds on other projects]       Didn't go into this one which it should have
Regular expression run condition: Expression=[.*(NAP-Server|NAP-ALL)+], Label=[NAP-Client,NAP-Server]     Went into this one as it should have
Run condition [Regular expression match] enabling perform for step [Trigger/call builds on other projects]
Returning node parameter for master
Waiting for the completion of NAP-Server
NAP-Server #98 completed. Result was SUCCESS
Regular expression run condition: Expression=[.*(NAP-Reports|NAP-ALL)+], Label=[NAP-Client,NAP-Server]    Didn't go in as it shouldn't have
Run condition [Regular expression match] preventing perform for step [Trigger/call builds on other projects]    
Regular expression run condition: Expression=[.*(CAS|NAP-ALL)+], Label=[NAP-Client,NAP-Server]     Didn't go in as it shouldn't have
Run condition [Regular expression match] preventing perform for step [Trigger/call builds on other projects]
Warning: you have no plugins providing access control for builds, so falling back to legacy behavior of permitting any downstream builds to be triggered

 

Is it having a problem with the ".*" because NAP-Client occurs at the beginning of the line?


 

-- 

Eric Pyle

unread,
Mar 1, 2016, 11:54:57 AM3/1/16
to jenkins...@googlegroups.com
You need ".*" instead of "+" after the close parentheses. Otherwise you are only able to match the second entry in your label, because you are not allowing anything after the matched label.

Eric
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

Eric Fetzer

unread,
Mar 1, 2016, 12:14:42 PM3/1/16
to Jenkins Users
Exactly, I'm just trying to build two of the 4 possible projects based on this call.  I put the comma in there for readability.  The other side is the regex.  The regex should always match the one with ALL in it because if I pass that, I want it to build every single one of them.  Your suggestion changing it to .* at the end works like a champ, THANKS!  I feel kind of dumb not having caught that myself...



On Monday, February 29, 2016 at 2:32:08 PM UTC-7, Eric Fetzer wrote:

Eric Pyle

unread,
Mar 8, 2016, 9:02:06 AM3/8/16
to jenkins...@googlegroups.com
I believe the * following the closing parentheses means "zero or more occurrences of", and in this case applies to the contents of the parentheses. So it's matching on zero occurrences. You probably want ").*"

Eric
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

Gmail Account

unread,
Mar 8, 2016, 1:35:36 PM3/8/16
to jenkins...@googlegroups.com
Yep, that works, thanks!
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/2lxINpDeGUo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/56D5ACDD.9000708%40cd-adapco.com.
Reply all
Reply to author
Forward
0 new messages