Search code examples
jenkinsjenkins-pipelinejenkins-plugins

Jenkins text finder


Im currently working with this Jenkins Plugin https://www.jenkins.io/doc/pipeline/steps/text-finder/ https://plugins.jenkins.io/text-finder/#documentation I`ve tried to make a pipline and do the following:

pipeline {
    agent any

    stages {
        stage('Hello') {
            steps {
                findText(textFinders: [textFinder(regexp: '<Started by>', alsoCheckConsoleOutput: true, buildResult: 'UNSTABLE')])
            }
        }
    }
}

This code succeeds, finds the desired text, but buildResult/unstableIfFound parameters seem to never work for me: the job finishes with SUCCESS status. Can anybody help me with that? Or recommend any other option to parse Jenkins console logs and mark the build unstable in some cases ? Thanks in advance!


Solution

  • Yes you can do it by using manager.log feature parse the jenkins console log output. Please install postbuild plugin and then try

         try {
            something
          } catch (e) {
            if ( manager.logContains('.*Add the text message which you want find and mark build unstable.*') {
              catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') {
                error('The build is failed because above test.')
              }
            }