0

I tried the below OR (||) expecting the build to fail if any of the myTeststring1 OR MyTestString2 matches the console output. I tried few other ways with ||, it doesn't work. Any suggestion?

if (manager.logContains('.myTestString1.') || ('.myTestString2.')) { error("Build failed because of this and that..")

  • This is really a generic programming question, but you forgot to put the method name with the 2nd parenthesis. So it was evaluated as conversion from string to boolean, which made it always true and the constant string is not empty, making the entire expression always true. This is not a good question for this site as the answer will not help anyone else, I'd suggest you retract it. – Jiri Klouda Apr 8 at 17:32
  • If this is what you mean, I tried it too and multiple different combinations but it didn't help: if (manager.logContains('.*String.*'))|| (manager.logContains('.*String4.*')) { error("Build failed because of this and that..SECOND") } – Narasimha Apr 9 at 13:01
  • The code from comment should actually work. You can also do the or inside the regex manager.logContains(".*(String1|String4).*") Have you tried to use double quotes instead of single quotes? Either way the answer is the same, not really a question that will benefit anyone else: docs.groovy-lang.org/latest/html/documentation/… – Jiri Klouda Apr 9 at 22:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.