2

What would be a Groovy or pipeline step to parse Jenkins console output, identify a string and mark the build as failure if the string is matched?

  • 1
    When you say "pipeline" - do you mean "declarative pipeline"? – Bruce Becker Nov 7 '18 at 11:05
2

This question seems similar to another on StackOverflow, but seems to be a close, but not exact duplicate of https://stackoverflow.com/questions/37018509/jenkinsfile-build-log

To quote those :

if you just want to check, that your log contains string myTestString you can just call manager.logContains('.myTestString.')

If you want to get some information from the first matching line you can use manager.getLogMatcher(regexp)

You could use the Groovy flow control to break the build - you just need a step to execute the test:

Following the example on the link :

node {
    stage('CheckLog') {
      steps {
        if (manager.logContains('.*myTestString.*')) {
          error("Build failed because of this and that..")    
        }
      }
    }
  • the other two questions which this is similar to don't actually ask how to fail the build based on the contents of the log, just how to get the contents of the log, so technically, this is not a duplicate. – Bruce Becker Nov 7 '18 at 11:34
  • Agree with the not duplicate, and usually we do not close cross duplicates unless there's really no more in this site approach on the question than the other site. In brief good job bringing this together and adding the missing point – Tensibai Nov 7 '18 at 12:56
  • Bruce, what if I want to match multiple patterns like if (manager.logContains('.*myTestString.*') || ('.*myTestString2.*')) )? I tried multiple options but it don't work. Any suggestion? – Narasimha Apr 6 at 6:10

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.