[英]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.