2016-08-02 139 views
9

当maven工作不稳定(黄色)时,我的管道目前失败(红色)。如果步骤不稳定,Jenkins管道失败

node { 
    stage 'Unit/SQL-Tests' 
    parallel (
     phase1: { build 'Unit-Tests' }, // maven 
     phase2: { build 'SQL-Tests' } // shell 
    ) 
    stage 'Integration-Tests' 
    build 'Integration-Tests' // maven 
} 

在此示例中,作业Unit-Test的结果不稳定,但在管道中显示为失败。

如何更改作业/管道/ jenkins使(1)管道步骤不稳定而不是失败,以及(2)管道状态不稳定而不是失败。

我试着加入MAVEN_OPTS参数-Dmaven.test.failure.ignore=true,但那并没有解决问题。我不确定如何将build 'Unit-Test'包装到可以捕获和处理结果的逻辑中。

使用this logic添加子管道并不能解决问题,因为没有选项可以从subversion检出(该选项在常规的maven作业中可用)。如果可能的话,我不想使用命令行签出。

回答

10

无论步骤是不稳定还是失败,脚本中的最终生成结果都将失败。

默认情况下,您可以将传播添加到false以避免流失败。

def result = build job: 'test', propagate: false 

在流程结束时,您可以根据从“result”变量得到的结果来判断最终结果。

例如

currentBuild.result='UNSTABLE' 

这里是一个详细例子 How to set current build result in Pipeline

BR,

13

教训:

  • 个詹金斯将根据currentBuild.result值其可以是SUCCESSUNSTABLEFAILED
  • build job: <JOBNAME>结果可以被存储在一个变量连续地更新所述管道。构建状态为variable.result
  • build job: <JOBNAME>, propagate: false将会阻止整个构建立即失败。
  • currentBuild.resultcan only get worse。如果该值是以前FAILED并通过currentBuild.result = 'SUCCESS'接收新的状态SUCCESS它会留FAILED

这是我最后使用:

node { 
    def result // define the variable once in the beginning 
    stage 'Unit/SQL-Tests' 
    parallel (
     phase1: { result = build job: 'Unit', propagate: false }, // might be UNSTABLE 
     phase2: { build 'SQL-Tests' } 
    ) 
    currentBuild.result = result.result // update the build status. jenkins will update the pipeline's current status accordingly 
    stage 'Install SQL' 
    build 'InstallSQL' 
    stage 'Deploy/Integration-Tests' 
    parallel (
     phase1: { build 'Deploy' }, 
     phase2: { result = build job: 'Integration-Tests', propagate: false } 
    ) 
    currentBuild.result = result.result // should the Unit-Test be FAILED and Integration-Test SUCCESS, then the currentBuild.result will stay FAILED (it can only get worse) 
    stage 'Code Analysis' 
    build 'Analysis' 
} 
+2

而且你不能设置一个'SUCCESS'结果,如果它已被设置为'FAILED'(如[在此讨论](http://stackoverflow.com/questions/38221836/how-to-manipulate-the-build-result-of-a-jenkins-pipeline-job))。 – StephenKing

+1

感谢您的信息。已将该问题添加到答案中。 – michaelbahr

+0

我遇到同样的问题,但我不明白原因。为什么如果Stage View插件支持不稳定(黄色),Unstable被认为是FAILED?为什么你需要一直设置currentBuild.result,而不是采取最糟糕的一切? – lqbweb

相关问题