emailext-仅在html报告可用时才发送电子邮件,否则不应通过电子邮件发送

时间:2018-08-29 20:02:15

标签: jenkins jenkins-plugins

我的目标是-通常 emailext 发送带有错误消息的电子邮件,例如

  

错误:文件'path / to / index.html'不存在

我的代码如下

emailext(to: 'jane.doe@foo.com',
        subject: 'Build report',
        mimeType: 'text/html',
        body: '${FILE,path="path/to/index.html"}',
)

此错误消息是正确的。没有产生html报告。但是我希望仅当有html报告时才发送此电子邮件,而在没有html报告时发送错误消息。

关于如何实现这种行为的任何想法?

非常感谢!

1 个答案:

答案 0 :(得分:0)

您可以使用groovy的File.exists方法检查给定文件是否存在,并相应地运行脚本。

def file = new File( 'path/to/index.html' )

// If it exists
if( file.exists() ) {
  emailext(to: 'jane.doe@foo.com',
        subject: 'Build report',
        mimeType: 'text/html',
        body: '${FILE,path="path/to/index.html"}',
  )
}
相关问题