[英]Jenkins pipeline: fail build on string found in build console
您可以使用Log Parser插件 ,该插件也支持Jenkins Pipeline作业。 它为我们工作。
我们在Manage Jenkins->Configure System->Console Output Parsing
配置了一些全局规则。 在那里配置的文件放置在Jenkins Master可以访问的位置,例如
# /home/jenkins/default.rules (on the jenkins master machine)
error /ERROR/
例如,有一个名为“默认”的规则集,它引用/home/jenkins/default.rules' you could use the following (the
you can get using the snippet generator selecting
默认规则you can get using the snippet generator selecting
parsingRulesPath):
echo "ERROR: Some error"
node {
step([$class: 'LogParserPublisher',
failBuildOnError: true,
parsingRulesPath: '/home/jenkins/default.rules',
useProjectRule: false])
}
原来,不需要全局配置条目。 您还可以使用工作空间中的规则,例如:
echo "ERROR: Some error"
node {
// Usually I assume a project rules file will be stored in
// some repository and are not generated on the fly
writeFile(file: 'project.rules', text:
'''
error /ERROR/
''')
step([$class: 'LogParserPublisher',
failBuildOnError: true,
projectRulePath: 'project.rules',
useProjectRule: true])
}
尽管上面的示例是针对脚本化管道的,但也应该很容易将它们应用于声明性管道。
这有效
pipeline {
agent any
stages {
stage('Build') {
steps {
sh '''
echo Blabla
echo FATAL error
'''
}
}
stage('Results') {
steps {
script {
def logz = currentBuild.rawBuild.getLog(10000);
def result = logz.find { it.contains('FATAL') }
if (result) {
error ('Failing due to ' + result)
}
}
}
}
}
}
但需要获得詹金斯(Jenkins)管理员的一些脚本批准。
并且有一个批准请求,其中指出“批准此签名可能会引入安全漏洞! 建议您拒绝它。 ”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.