我在声明性管道中使用Cucumber reports plugin >
public void method1(){
try{
//anything
}
catch(Exception e){
Log.error(e);
throw e;
}
}
public void method2(){
try{
//anything
}
catch(Exception e){
Log.error(e);
throw e;
}
}
public void method3(){
try{
//anything
}
catch(Exception e){
Log.error(e);
throw e;
}
}
public void method4(){
try{
//anything
}
catch(Exception e){
Log.error(e);
throw e;
}
}
我能够通过侧边栏上的链接检查某些测试是否失败,但是如果某些黄瓜报告失败,我是否需要做一些事情来标记包含let arrTouple = [(0, 1), (0, 1), (0, 1), (0, 1), (0, 1), (0, 1), (0, 1), (0, 1), (0, 1), (0, 1)]
let arr = arrTouple.flatMap{ [$0, $1] }
print(arr) // [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]
检查的阶段是否失败?因为问题是尽管黄瓜报告有些失败,但是构建和阶段都是绿色且成功的。
Jenkins版本为2.176.3
黄瓜报告版本为4.10.0
答案 0 :(得分:1)
无论测试结果如何,您使用的黄瓜命令仅会生成报告。 所以是的,您必须使管道以某种方式失败,因为您面临的问题是您的测试命令没有返回使管道失败。
一种解决方法是,如果测试出现问题,则运行测试的命令将返回非零退出代码(退出1)。那会使您的管线阶段变红。
如果您使用Maven运行测试,则可以在“ mvn测试”(或任何其他方式)上自动进行管理。 否则,如果您无法执行此操作,则必须设法制作类似sh脚本的内容 返回退出代码(0通过/ 1失败)或在'script'标记内的常规函数设置管道的currentBuild.result值:
def checkTestResult() {
// Check some file to see if tests went fine or not
return 'SUCCESS' // or 'FAILURE'
}
...
stage {
script {
currentBuild.result = checkTestResult()
if (currentBuild.result == 'FAILURE') {
sh "exit 1" // Force pipeline exit with build result failed
}
}
}
...
我建议您对声明性管道的“始终”后期构建操作使用黄瓜命令 因为这是您可能会在管道结束时每次通过或失败时都执行的步骤。请参见以下示例:
pipeline {
stages {
stage('Get code') {
// Whatever
}
stage('Run tests') {
steps {
sh "mvn test" // run_tests.sh or groovy code
}
}
}
post {
always {
cucumber '**/cucumber.json'
}
}
}
答案 1 :(得分:0)
如果报告标记为失败,则可以将BuildStatus : 'FAILURE'
设置为将构建标记为失败。
cucumber fileIncludePattern: '**/cucumber.json', buildStatus: 'FAILURE'