栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在管道工作流程中使用Jenkins'Mailer'

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在管道工作流程中使用Jenkins'Mailer'

在Pipeline中,失败

sh
不会立即将设置为
currentBuild.result
FAILURE
而初始值为
null
。因此,依赖于诸如Mailer之类的构建状态的构建步骤可能看起来不正确。

您可以通过添加调试打印来检查它:

stage 'Test'node {    try {        sh 'exit 1'    } finally {        println currentBuild.result  // this prints null        step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'me@me.com', sendToIndividuals: true])    }}

整个流程都由Jenkins提供的异常处理程序包装,这就是Jenkins最终将构建标记为失败的原因。

因此,如果您想使用Mailer,则需要正确维护构建状态。例如:

stage 'Test'node {    try {        sh 'exit 1'        currentBuild.result = 'SUCCESS'    } catch (any) {        currentBuild.result = 'FAILURE'        throw any //rethrow exception to prevent the build from proceeding    } finally {        step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'me@me.com', sendToIndividuals: true])    }}

如果您不需要重新抛出异常,则可以使用

catchError
。它是内置的Pipeline,可捕获其范围内的任何异常,将其打印到控制台中并设置构建状态。例:

stage 'Test'node {    catchError {        sh 'exit 1'    }     step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'me@me.com', sendToIndividuals: true])}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/393424.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号