问题
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)
}
}
}
}
}
回答1:
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.
回答2:
pipeline {
agent {
label {
label "master"
}
}
stages {
stage('CHECKOUT') {
steps{
script{
echo "##[1 / 4] ERROR"
}
publishers {
findText regexp: failure, alsoCheckConsoleOutput: true notBuiltIfFound: true
}
}
}
}
}
回答3:
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?
来源:https://stackoverflow.com/questions/48450640/jenkins-text-finder-plugin-how-can-i-use-this-plugin-with-jenkinsfile