如果任何测试用例使用 findText 插件失败,如何使 jenkins 构建失败

时间:2021-06-18 09:45:00

标签: jenkins jenkins-pipeline pipeline declarative

我在 Jenkins 中有一个阶段,如下所示,如果测试用例失败,我如何将构建标记为失败或不稳定?我为 textfinder 插件生成了脚本管道,但它不起作用。 "findText alsoCheckConsoleOutput: true, regexp: 'There are test failures.',unstableIfFound: true" 不知道在哪里放置 textFinder 正则表达式。

管道{

agent none
tools {
    maven 'maven_3_6_0'
    
}

options {
    timestamps ()
    buildDiscarder(logRotator(numToKeepStr:'5'))
}

environment {
    JAVA_HOME = "/Users/jenkins/jdk-11.0.2.jdk/Contents/Home/"
    imageTag = ""
}

parameters {
    choice(name: 'buildEnv', choices: ['dev', 'test', 'preprod', 'production', 'prodg'], description: 'Environment for Image build')
    choice(name: 'ENVIRONMENT', choices: ['dev', 'test', 'preprod', 'production', 'prodg'], description: 'Environment for Deploy')
}

stages {
    stage("Tests") {
        agent { label "xxxx_Slave"}
            steps {
                checkout([$class: 'GitSCM', branches: [[name: 'yyyyyyyyyyz']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'zzzzzzzzzzz', url: 'abcdefgh.git']]])
                sh'''
                cd dashboard
                mvn -f pom.xml surefire-report:report -X -Dsurefire.suiteXmlFiles=src/test/resources/smoke_test.xml site -DgenerateReports=false
                '''
            }
            
    }
}

}

1 个答案:

答案 0 :(得分:0)

为了使这个请求成为可能,我所做的一切如下:

在步骤块代码下方添加了一个后代码块。

发布{ 成功 { findText alsoCheckConsoleOutput:true,refexp:'有测试失败。',unstableIfFound:true } }