I've got a regex with sample text that is working on regex101, but doesn't seem to work in my Jenkins pipeline scenario. So I'm assuming I've got a mistake in my pipeline script, but I fail to see where.
Here's a repro:
pipeline {
agent any
stages {
stage ('Test') {
steps {
script {
echo ("Test")
output = "Some text. \n\n 12 scenarios (3 failed, 2 success) plus text \n\n and some more text"
def hasSummaryMatch = (output ==~ /\d+ scenarios \([^()]+\)/)
echo ("hasSummaryMatch = " + hasSummaryMatch)
if (!hasSummaryMatch) {
error ("No summary!")
}
}
}
}
}
}
I've tested this with Jenkins 2.60.2 running in the official Docker container.
This provides the following (abbreviated) output:
Started by user Administrator
Running on master in /var/jenkins_home/workspace/Test001
Test
hasSummaryMatch = false
ERROR: No summary!
Finished: FAILURE
The expected output is no error because there should be a match.
What am I doing wrong?
Just use =~
(the find operator) instead of ==~
(the match operator):
def hasSummaryMatch = (output =~ /\d+ scenarios \([^()]+\)/)
When match operator ==~
is used, then a strict match of the input string required
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With