【问题标题】:How to change Jenkins build status if failed scenarios were successfully reruned如果成功重新运行失败的场景,如何更改 Jenkins 构建状态
【发布时间】:2019-01-17 21:44:41
【问题描述】:

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

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

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

MainTestRunner:

@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();
}
}

FailedTestRunner:

@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 {}

【问题讨论】:

  • 你是如何从 Jenkins 触发测试的?
  • 我是通过 maven 触发的。
  • 您可能希望将其作为 shell 脚本运行。设置 e 然后 mvn test 然后以某种方式读取失败数据,可能在侦听器中写入失败计数并在脚本中读取,然后相应地退出。

标签: java jenkins testng cucumber-java


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    主要目标是在第二次测试运行成功后获得“绿色”Jenkins 状态。
    我又添加了一个构建步骤。 现在我正在使用:

    mvn clean test -Dmaven.test.failure.ignore=true
    

    将所有失败的测试记录到 rerun.txt 文件中。
    并且:

    mvn test -Dtest=runners.FailedTestRunner -DfailIfNoTests=false
    

    运行它。

    【讨论】:

      猜你喜欢
      • 2020-06-11
      • 1970-01-01
      • 1970-01-01
      • 2017-08-23
      • 1970-01-01
      • 1970-01-01
      • 2016-03-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多