dmsantaterra
dmsantaterra

Reputation: 53

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)
                }
            }
        }
    }
}

Upvotes: 5

Views: 10252

Answers (3)

10raw
10raw

Reputation: 574

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

Upvotes: 3

lvthillo
lvthillo

Reputation: 30801

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.

Upvotes: 4

mghicks
mghicks

Reputation: 1174

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?

Upvotes: 0

Related Questions