0

My Jenkins task searches the console output to see if the build is stable. It searches this java pattern: exception|error|warning|Segmentation

I have a compile parameter that has -Werror=format-security in it, so Jenkins should not match it. I try this [exception|error|warning|Segmentation][^Werror] but it still finds Werror in the text. How can I make it so it doesn't think my build is unstable because of compile parameter?

5
  • 1
    Try ^(?!.*Werror).*(?:exception|error|warning|Segmentation) Commented Oct 3, 2017 at 7:41
  • But is this java regex pattern? The test failed regexplanet.com/advanced/java/index.html or I am wrong. Commented Oct 3, 2017 at 7:44
  • 1
    No idea how you tested and against what strings. See this RegexPlanet demo (click "Java" to see the result, find() finds a partial match in the second string). Commented Oct 3, 2017 at 7:46
  • You're right. it works at Jenkins as I wanted. I probably don't understand that test page's output. Commented Oct 3, 2017 at 7:57
  • Glad to help. I posted an answer. Note that Java supports all the constructs used in the pattern: ^ anchor, (?!...) negative lookahead, greedy matching and (?:...|...) non-capturing alternation groups. Commented Oct 3, 2017 at 8:09

1 Answer 1

2

You may use

^(?!.*Werror).*(?:exception|error|warning|Segmentation)

See the RegexPlanet demo.

Details

  • ^ - start of string
  • (?!.*Werror) - there must not be a Werror substring anywhere on the line
  • .* - any 0+ chars other than line break chars as many as possible
  • (?:exception|error|warning|Segmentation) - one of the values inside the non-capturing alternation group.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.