我正在尝试使用编写 jenkinsfile文本查找器插件 https://wiki.jenkins.io/display/JENKINS/Text-finder+Plugin,但我不知道它到底是如何工作的。
这是我的代码:
pipeline {
agent {
label {
label "master"
}
}
stages {
stage('CHECKOUT') {
steps{
script{
echo "##[1 / 4] ERROR"
}
publishers {
textFinder("*ERROR*", '', true, false, true)
}
}
}
}
}
正如 @mghicks 已经提到的,并非每个插件都支持 Jenkins 管道。在这种情况下,文本查找器插件不支持它。
例如,您可以为其编写自己的常规函数:
例如:
pipeline {
agent {
label {
label "master"
}
}
stages {
stage ('Check logs') {
steps {
filterLogs ('ERROR', 2)
}
}
}
}
我们正在调用函数filterLogs,并提供参数“ERROR”(在日志中搜索“ERROR”一词),并定义“ERROR”一词的出现(当“ERROR”一词出现两次时,会使作业不稳定):
我们的 filterLogs 函数如下所示:
#!/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'
}
}
如果您不使用共享库或其他东西,您也可以在管道内部实现该函数。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)