黄瓜4 jvm使用shell命令在jenkins中重新运行失败的测试

时间:2019-05-29 15:25:07

标签: jenkins gradle cucumber cucumber-jvm

我在jenkins shell命令中添加了执行命令:

cd apitests && ./gradlew cucumber -Pthreads=${THREADS} -Ptags="not @notReady" && [ -s rerun/failed_scenarios.txt ] && ./gradlew cucumber -PfeaturePath='@rerun/failed_scenarios.txt' -Pthreads=80 || echo "File empty"

在gradle中,我添加了带有黄瓜选项的任务,我将其设置为将失败的测试保存到文件:

cucumber {
    threads = 50
    glue = 'classpath:com.sixtleasing.cucumber.steps'
    plugin = ["pretty", "html:target/zucchini", "json:target/zucchini.json", "rerun:rerun/failed_scenarios.txt"] 
    (...)
}

所有测试均为绿色时,一切正常。当其中一项测试失败时,问题开始。在那种情况下,我会在控制台中看到:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':cucumber'.
> java.lang.RuntimeException: The execution failed

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

为什么?如果我分别运行命令,则可以运行,但是在詹金斯中,它是一个shell命令,

1 个答案:

答案 0 :(得分:0)

如果第一次用黄瓜调用gradle失败,那么将不执行&&右侧的任何操作。这是因为如果构建失败,则gradlew进程的返回码将为非零。

尝试一下:

cd apitests && ./gradlew cucumber -Pthreads=${THREADS} -Ptags="not @notReady" || ( [ -s rerun/failed_scenarios.txt ] && ./gradlew cucumber -PfeaturePath='@rerun/failed_scenarios.txt' -Pthreads=80 || echo "File empty" )