mic*_*ahr 17 maven jenkins jenkins-pipeline jenkins-2
目前我的管道失败(红色),当maven作业不稳定(黄色).
node {
stage 'Unit/SQL-Tests'
parallel (
phase1: { build 'Unit-Tests' }, // maven
phase2: { build 'SQL-Tests' } // shell
)
stage 'Integration-Tests'
build 'Integration-Tests' // maven
}
Run Code Online (Sandbox Code Playgroud)
在此示例中,作业Unit-Test的结果不稳定,但在管道中显示为失败.
如何更改jobs/pipeline/jenkins以使(1)管道步骤不稳定而不是失败,以及(2)管道状态不稳定而不是失败.
我尝试添加MAVEN_OPTS参数-Dmaven.test.failure.ignore=true,但这并没有解决问题.我不确定如何将build 'Unit-Test'一些可以捕获和处理结果的逻辑包装起来.
使用此逻辑添加子管道并不起作用,因为没有从subversion签出的选项(该选项在常规maven作业中可用).如果可能的话,我不想使用命令行结帐.
mic*_*ahr 23
得到教训:
currentBuild.result可以是任一值SUCCESS,UNSTABLE或者FAILURE(源).build job: <JOBNAME>可以存储在变量中.构建状态为variable.result.build job: <JOBNAME>, propagate: false 将阻止整个构建立即失败.currentBuild.result 只能变得更糟.如果该值以前是FAILED并且SUCCESS通过currentBuild.result = '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'
}
Run Code Online (Sandbox Code Playgroud)
Tim*_*Tim 19
无论步骤是不稳定还是失败,脚本中的最终构建结果都将失败.
默认情况下,您可以将传播添加到false,以避免流失败.
def result = build job: 'test', propagate: false
Run Code Online (Sandbox Code Playgroud)
在流程结束时,您可以根据您从"结果"变量获得的内容来判断最终结果.
例如
currentBuild.result='UNSTABLE'
Run Code Online (Sandbox Code Playgroud)
以下是如何在Pipeline中设置当前构建结果的详细示例
BR,
蒂姆
| 归档时间: |
|
| 查看次数: |
29054 次 |
| 最近记录: |