Jenkins Text finder Plugin, How can I use this plugin with jenkinsfile?

I am trying write a jenkinsfile using Text Finder plugin, but I don't know exactly how it works.

Here's my code:

pipeline {
    agent {
        label {
            label "master"
        }            
    }
    stages {
        stage('CHECKOUT') {
            steps{
                script{
                    echo "##[1 / 4] ERROR"
                }
                publishers {
                    textFinder("*ERROR*", '', true, false, true)
                }
            }
        }
    }
}

As @mghicks already mentions, not every plugin supports Jenkins pipelines. In this case the Text Finder plugin is not supporting it. You can for example write your own groovy function for it:

For example:

pipeline {
    agent {
        label {
            label "master"
        }            
    }

    stages {
        stage ('Check logs') {
            steps {
                filterLogs ('ERROR', 2)
            }
        }
    }
}

We are calling a function filterLogs and we provide the parameters 'ERROR' (search for the word ERROR in your logs) and we define the occurence of the word 'ERROR' (when the word ERROR is there 2 times, than make the job unstable):

Our filterLogs function looks like:

#!/usr/bin/env groovy

import org.apache.commons.lang.StringUtils

def call(String filter_string, int occurrence) {
    def logs = currentBuild.rawBuild.getLog(10000).join('\n')
    int count = StringUtils.countMatches(logs, filter_string);
    if (count > occurrence -1) {
        currentBuild.result='UNSTABLE'
    }
}

You can also just implement the function just inside your pipeline if you are not using shared libraries or something.

Text Finder, This plugin is used to search for strings in workspace files. The outcome of this search can be used to downgrade the build status. This plugin lets you search for some text using regular expressions in a set of files or the console log. Based on the outcome, you can downgrade the build result to UNSTABLE, FAILURE, NOT_BUILT, or ABORTED. For example, you can search for the string failure in a set of log files.

pipeline {
    agent {
        label {
            label "master"
        }            
    }
    stages {
        stage('CHECKOUT') {
            steps{
                script{
                    echo "##[1 / 4] ERROR"
                }
                publishers {
                    findText regexp: failure, alsoCheckConsoleOutput: true notBuiltIfFound: true
                }
            }
        }
    }
}

Text Finder, The following plugin provides functionality available through Pipeline-compatible steps. Read more about how to integrate steps into your Pipeline in the Steps� Using a text editor, ideally one which supports Groovy syntax highlighting, create a new Jenkinsfile in the root directory of the project. The Declarative Pipeline example above contains the minimum necessary structure to implement a continuous delivery pipeline.

Plugins need to enable pipeline support--it's not automatic. Given the Text Finder plugin hasn't been updated since Jan 2014, and I don't see it in the list of pipeline steps, it simply may not be possible. For a potential workaround see How to use Jenkins plugins with no pipeline support?

Text-finder Plugin - Jenkins, This plugin lets you search for some text using regular expressions in a set of files or the console log. Once a match is found, you can� Text Finder Plugin. This plugin lets you search for some text using regular expressions in a set of files or the console log. Based on the outcome, you can downgrade the build result to UNSTABLE, FAILURE, NOT_BUILT, or ABORTED. For example, you can search for the string failure in a set of log files.

Text Finder Wiki, Text Finder Wiki. This plugin is used to search for strings in workspace files. The outcome of this search can be used to mark the build as normal or failed. The Text Finder plugin also has the advantage of working for jobs that don't have the Groovy Sandbox enabled. I'm not sure I understand what you mean by that. A blog post from Tyler Croy strongly recommends to not disable the Groovy Sandbox. I don't disable the Groovy Sandbox and I use the Groovy Post Build Plugin throughout my Jenkins

textFinder, textFinder. Requires Text Finder Since 1.19 Searches for keywords in files or the console log and uses that to downgrade a build to be unstable or a failure. If you select option Remote Jenkinsfile Provider Plugin tries to find matching branch in a repository which defined in Plugin SCM definition with in the Branch Sources SCM definition. By this, Jenkins Files will be used in the branch of Jenkins File repository which have the same branch name in code source repository.

Tweaking Jenkins Result using Plugin Text Finder, So via this blog, I am trying to explain how to tweak Jenkins results using text finder plug-in. How to get a blue build even if your test case fails. The initialization of� This plugin enables you to set environment variables via a file. The file's format must be the standard Java property file format.. Superseded by the EnvInject Plugin?. The property file is always retrieved from the file system of the Jenkins master node, even in distributed setups with slave nodes.

Comments
  • TextFinder supports now pipelines: issues.jenkins-ci.org/browse/JENKINS-34983
  • This is not really relevant for Jenkins pipelines. the mentioned below is correct. This solution requires you to get into java under the hood, which is an evil step for people who are running other languages and deployments.
  • Now there is indeed a better solution below. But this solution didn't exist 2 years ago. Writing groovy scripts for your pipelines has no disadvantage and has nothing to do with which language you are building/deploying. Jenkins supports a shared library setup in which you can write reusable .groovy scripts so you can manage the magic in one place and resuse it in multiple pipelines: jenkins.io/doc/book/pipeline/shared-libraries
  • Quite a strange link to workaround. It states "No. You can't".
  • @AndreyRegentov I agree. I wonder if anyone is able to see the history of that question--did it used to have another answer? I don't think I would have linked to that as it looks today.