【问题标题】:emailext - should send email only if html report is available else should not emailemailext - 仅当 html 报告可用时才应发送电子邮件,否则不应发送电子邮件
【发布时间】:2018-08-30 05:26:11
【问题描述】:

我的目标是 -- 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 报告时发送错误消息。

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

非常感谢!

【问题讨论】:

    标签: jenkins jenkins-plugins


    【解决方案1】:

    您可以使用 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"}',
      )
    }
    

    【讨论】:

    猜你喜欢
    • 2013-02-18
    • 1970-01-01
    • 2011-03-30
    • 2011-09-16
    • 2018-09-15
    • 2021-05-06
    • 1970-01-01
    • 2019-11-21
    • 1970-01-01
    相关资源
    最近更新 更多