I am trying to use Jenkins Conditional step plugin, to trigger a shell script if the current job has a certain pattern in its log, say "Keep one snapshot per week".
I guess I need to use the "Regular expression match" from conditional step plugin, but how should I configure the Expression and Label values ?
Thanks
The first step is to get the log content, that will be the input for the regex to match. This is done by setting Label with :
${BUILD_LOG_REGEX,regex="Keep one snapshot per week"}
(note : after selecting "regular expression match" in the combo box when configuring the plugin, you can click on the question mark to get the list of existing tokens like BUILD_LOG_REGEX that are available to use)
when this will be executed, if the log actually contains the string, the returned value will be something like :
Label=[[...truncated 1515 lines...]
[INFO] [05:10:55.472] -> Keep one snapshot per week between 2016-03-10 and 2017-02-09
[...truncated 22 lines...]
]
So now, we need to find the regex that matches exactly the label content, ie whatever is between the external brackets, including the blank characters. In the case above, we can configure Expression with :
^.*\s.*Keep one snapshot per week.*\s\[.*\s*
"\s" matches any space, tab or newline character.
Then you should see in the job logs something like this, confirming it's matching :
Regular expression run condition: Expression=[^.*\s.*Keep one snapshot per week.*\s\[.*\s*], Label=[[...truncated 1515 lines...]
[INFO] [05:10:55.472] -> Keep one snapshot per week between 2016-03-10 and 2017-02-09
[...truncated 22 lines...]
]
Run condition [Regular expression match] enabling perform for step [Execute shell]