首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Jenkinsfile - Post操作避免状态的代码重复

Jenkinsfile - Post操作避免状态的代码重复
EN

Stack Overflow用户
提问于 2018-07-10 18:20:55
回答 1查看 267关注 0票数 2

我正在使用Jenkins管道来运行构建。

如何避免执行相同代码(失败和不稳定)的2个post状态的代码重复?

示例代码片段:

代码语言:javascript
运行
复制
  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"
    )
  }
EN

回答 1

Stack Overflow用户

发布于 2018-07-10 19:47:11

你可以写一个函数并使用它,f.e.

代码语言:javascript
运行
复制
 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"
    )
  }
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51262760

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档