java - 如果成功重新运行失败的场景,如何更改 Jenkins 构建状态

标签 java jenkins testng cucumber-java

我有两个 TestNG 运行程序来运行 cucumber 场景的主要范围和失败范围。如果 MainTestRunner 成功,Jenkins 构建状态为“成功”并且 FailedTestRunner 不会在 rerun.txt 中找到任何失败的场景。但是如果 MainTestRunner 出现失败场景并且它在 FailedTestRunner 的范围内重新运行并通过,那么 Jenkins 构建无论如何都会失败。

我需要一个解决方案来使构建状态为“绿色”,因为所有测试最终都通过了。

我的测试运行器没有什么特别的技巧:

主测试运行器:

@CucumberOptions(
        features = ".",
        glue = {"steps"},
        monochrome = true,
        format = {
                "pretty",
                "html:target/cucumber-pretty",
                "json:target/CucumberTestReport.json",
                "rerun:target/rerun.txt"
        })

public class MainTestRunner extends AbstractTestNGCucumberTests {
private TestNGCucumberRunner testNGCucumberRunner;

@BeforeClass(alwaysRun = true)
public void setUpClass() {
    testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());
}

@Test(description = "Runs Cucumber Feature", dataProvider = "features")
public void feature(CucumberFeatureWrapper cucumberFeature) {
    testNGCucumberRunner.runCucumber(cucumberFeature.getCucumberFeature());
}

@DataProvider
public Object[][] features() {
    return testNGCucumberRunner.provideFeatures();
}

@AfterClass(alwaysRun = true)
public void tearDownClass() {
    testNGCucumberRunner.finish();
}
}

失败的测试运行器:

@CucumberOptions(
    features = "@target/rerun.txt"
    , glue = {"steps"}
    , monochrome = true
    , format = {
    "pretty",
    "html:target/cucumber-pretty",
    "json:target/CucumberTestReport.json",
    "rerun:target/rerun.txt"
})

public class FailedTestRunner extends AbstractTestNGCucumberTests {}

最佳答案

如果我能看到您的管道步骤,那将有助于回答,但如果您通过 sh 步骤执行 cucumber 测试,那么您可以使用 returnStatus:true 获取执行的退出状态。如果 main 失败并且 sh 返回退出状态 > 0,那么您可以在不更改构建状态的情况下运行失败。如果重播失败,那么你让它返回一个失败的状态,如果主要通过,那么你可以跳过失败的。

关于java - 如果成功重新运行失败的场景,如何更改 Jenkins 构建状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54090819/

相关文章:

Java 13 : Why are javaFX runtime components missing?

java - Tomcat 中 tomcat-juli.jar 的多个实例

java - 如何在 Jenkins 中使用构建参数编辑 app.properties 文件

jenkins 下的 git clone/ssh

docker - 如何将 SSH 从 JENKINS 主机复制到 DOCKER 容器中?

java - 无法模拟 System.currentTimeMillis()

java - LazyInitializationException,同时使用 TestNG 对 Hibernate 实体类进行单元测试以在 Spring 中使用

java - 这似乎用红色下划线

java - 找到应用程序在 Android 操作系统世界中某处崩溃之前执行的代码中的最后一点?

java - Ant 通过 Jenkins : "BUILD SUCCESSFUL" in Console Output while build is still running