jenkins - Jenkinsfile - 发布操作避免状态代码重复
问题描述
我正在使用 Jenkins 管道来运行构建。
如何避免执行相同代码(失败和不稳定)的 2 个发布状态的代码重复?
示例代码片段:
post {
failure
{
emailext(
attachmentsPattern: '**/log.txt',
body: "Something is wrong with ${env.BUILD_URL}",
subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
to: "test@test.gmail"
)
}
unstable
{
emailext(
attachmentsPattern: '**/log.txt',
body: "Something is wrong with ${env.BUILD_URL}",
subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
to: "test@test.gmail"
)
}
解决方案
你可以写一个函数并使用它,fe
post {
failure
{
sendMail()
}
unstable
{
sendMail()
}
def sendMail() {
emailext(
attachmentsPattern: '**/log.txt',
body: "Something is wrong with ${env.BUILD_URL}",
subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
to: "test@test.gmail"
)
}
推荐阅读
- python - 使用 value_counts 将新列添加到数据框
- smtp - Gmail smtp 无法发送电子邮件 javax.mail.AuthenticationFailedException:
- node.js - 在后续意图中获取与原始意图不匹配的参数值
- javascript - 如何在继续之前确保异步函数返回值
- java - 使用中位数 3 的快速排序中的逻辑错误
- python - 使用 Linux 子系统在 Python (os.subprocess) 中调用外部 bash 命令
- webgl - 获取 webGL2 片段着色器上的当前像素位置
- javascript - 如何在 d3 中从 v4 转换为 v3
- woocommerce - 在 woocommerce 帐户页面的下载选项卡上显示产品图片
- reactjs - docker 上没有 package.json