3

一旦作业成功运行,我正在使用 Jenking DSL 插件/Groovy 发送电子邮件。

   static void sendEmail(Job job, String jobName) {
    job.with {
        publishers {
            extendedEmail {
                recipientList('xyzcoders@xyz.com')
                defaultSubject("Jenkins Job started : ${jobName}")
                defaultContent("See the latest build in the jenkins job here https://jenkins.xyz.com/job/${jobName}/")
                contentType('text/html')
                triggers {
                    failure {
                        content("See the latest build in the jenkins job here https://jenkins.xyz.com/job/${jobName}/")
                        contentType('text/html')
                        recipientList('xyzcoder@xyz.com')
                        subject("Build Failed in Jenkins: ${jobName}")
                    }
                    success {
                        content('See the latest build in the jenkins job here https://jenkins.xyz.com/job/${jobName}/ <pre> ${BUILD_LOG, maxLines=30, escapeHtml=false} </pre>')
                        contentType('text/html')
                        recipientList('xyzcoder@xyz.com')
                        subject("Build Success in Jenkins: ${jobName}")
                    }
                }
            }
        }
    }
}

在内容部分

content('See the latest build in the jenkins job here https://jenkins.xyz.com/job/${jobName}/ <pre> ${BUILD_LOG, maxLines=30, escapeHtml=false} </pre>')

如果我使用单引号,那么我可以打印日志作为电子邮件的内容,但也不能打印作业名称,如果我使用双引号,那么我可以打印作业名称,但不能打印构建日志。

如何在电子邮件中同时打印作业名称和构建日志?

4

1 回答 1

2

字符串插值仅适用于双引号字符串,因此将引号更改为双引号。

当您说BUILD_LOG扩展之后不起作用时,var 不是由 Groovy 而是由 Jenkins 本身扩展的。所以尝试以下方法:

content("See the latest build in the jenkins job here https://jenkins.xyz.com/job/${jobName}/ " + '<pre> ${BUILD_LOG, maxLines=30, escapeHtml=false} </pre>')

或者你逃避$

content("See the latest build in the jenkins job here https://jenkins.xyz.com/job/${jobName}/ <pre> \${BUILD_LOG, maxLines=30, escapeHtml=false} </pre>")
于 2017-07-06T04:50:06.437 回答