在 Jenkins 管道上使用 Email-ext 插件在电子邮件正文中嵌入 html 报告?
Embed html report in email body using Email-ext plugin on Jenkins pipeline?
如何将电子邮件正文制作成 selenium html 报告。我已按照问题 Display HTML page inside mail body with Email-ext plugin in Jenkins 中给出的方法进行操作,但出现错误
org.codehaus.groovy.control.MultipleCompilationErrorsException:
startup failed: WorkflowScript: 6: unexpected token: FILE @ line 6,
column 17.
body: ${FILE,path="enteryPath/template.html"},
^
1 error
at org.codehaus.groovy.control.ErrorCollector.failIfErrors(
ErrorCollector.java:310)
at org.codehaus.groovy.control.ErrorCollector.addFatalError(
ErrorCollector.java:150)
at org.codehaus.groovy.control.ErrorCollector.addError(
ErrorCollector.java:120)
at org.codehaus.groovy.control.ErrorCollector.addError(
ErrorCollector.java:132)
at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:350)
at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(
AntlrParserPlugin.java:144)
at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(
AntlrParserPlugin.java:110)
at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:234)
at org.codehaus.groovy.control.CompilationUnit.call(
CompilationUnit.java:168)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(
CompilationUnit.java:943)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(
CompilationUnit.java:605)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(
CompilationUnit.java:581)
at org.codehaus.groovy.control.CompilationUnit.compile(
CompilationUnit.java:558)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(
CpsGroovyShell.java:129)
at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(
CpsGroovyShell.java:123)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(
CpsFlowExecution.java:517)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(
CpsFlowExecution.java:480)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(
WorkflowRun.java:269)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:421) Finished: FAILURE
我使用的代码是:
node {
stage ('email')
{
emailext (
subject: "some subject",
body: ${FILE,path="enteryPath/template.html"},
to: "email@example.com"
)
}
}
詹金斯版本 2.85
电子邮件扩展插件版本 2.60
谢谢
我已经通过以下代码修复了管道上的问题
emailext mimeType: 'text/html',
body: '${FILE,path="Seleniun/test-output/emailable-report.html"}',
subject: 'Selenium: Job '${env.JOB_NAME}' Status: currentBuild.result,
to: EMAIL_ADD
如果您使用自定义路径,此答案适合您
我在尝试实现这个结果时遇到了麻烦,因为我的路径是动态变化的,我不得不在 FILE
变量中使用一个变量。所以当我尝试以下任何一项时
body: '${FILE,path=${report}}'
body: "${FILE,path=${report}}"
body: '''${FILE,path=${report}}'''
还有很多,都没有用。另一方面,由于 Jenkins 限制
,我无法使用 groovy 读取文件
我的解决方法 是直接用 shell 阅读 html 就像这样
html_body = sh(script: "cat ${report}", returnStdout: true).trim()
然后发送邮件
emailext replyTo: '$DEFAULT_REPLYTO',
subject: "subject",
to: EMAIL,
mimeType: 'text/html',
body: html_body
其中 ${report}
是 html 文件的路径,例如 /var/jenkins/workspace_318/report.html
为了使用动态路径或评估变量路径,您可以执行以下操作:
" \ ${FILE,path= \ "${FILE_LOCATION} \ "}"
请注意反斜杠,空格需要剪掉。
如何将电子邮件正文制作成 selenium html 报告。我已按照问题 Display HTML page inside mail body with Email-ext plugin in Jenkins 中给出的方法进行操作,但出现错误
org.codehaus.groovy.control.MultipleCompilationErrorsException:
startup failed: WorkflowScript: 6: unexpected token: FILE @ line 6,
column 17.
body: ${FILE,path="enteryPath/template.html"},
^
1 error
at org.codehaus.groovy.control.ErrorCollector.failIfErrors(
ErrorCollector.java:310)
at org.codehaus.groovy.control.ErrorCollector.addFatalError(
ErrorCollector.java:150)
at org.codehaus.groovy.control.ErrorCollector.addError(
ErrorCollector.java:120)
at org.codehaus.groovy.control.ErrorCollector.addError(
ErrorCollector.java:132)
at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:350)
at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(
AntlrParserPlugin.java:144)
at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(
AntlrParserPlugin.java:110)
at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:234)
at org.codehaus.groovy.control.CompilationUnit.call(
CompilationUnit.java:168)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(
CompilationUnit.java:943)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(
CompilationUnit.java:605)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(
CompilationUnit.java:581)
at org.codehaus.groovy.control.CompilationUnit.compile(
CompilationUnit.java:558)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(
CpsGroovyShell.java:129)
at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(
CpsGroovyShell.java:123)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(
CpsFlowExecution.java:517)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(
CpsFlowExecution.java:480)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(
WorkflowRun.java:269)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:421) Finished: FAILURE
我使用的代码是:
node {
stage ('email')
{
emailext (
subject: "some subject",
body: ${FILE,path="enteryPath/template.html"},
to: "email@example.com"
)
}
}
詹金斯版本 2.85 电子邮件扩展插件版本 2.60 谢谢
我已经通过以下代码修复了管道上的问题
emailext mimeType: 'text/html',
body: '${FILE,path="Seleniun/test-output/emailable-report.html"}',
subject: 'Selenium: Job '${env.JOB_NAME}' Status: currentBuild.result,
to: EMAIL_ADD
如果您使用自定义路径,此答案适合您
我在尝试实现这个结果时遇到了麻烦,因为我的路径是动态变化的,我不得不在 FILE
变量中使用一个变量。所以当我尝试以下任何一项时
body: '${FILE,path=${report}}'
body: "${FILE,path=${report}}"
body: '''${FILE,path=${report}}'''
还有很多,都没有用。另一方面,由于 Jenkins 限制
,我无法使用 groovy 读取文件我的解决方法 是直接用 shell 阅读 html 就像这样
html_body = sh(script: "cat ${report}", returnStdout: true).trim()
然后发送邮件
emailext replyTo: '$DEFAULT_REPLYTO',
subject: "subject",
to: EMAIL,
mimeType: 'text/html',
body: html_body
其中 ${report}
是 html 文件的路径,例如 /var/jenkins/workspace_318/report.html
为了使用动态路径或评估变量路径,您可以执行以下操作:
" \ ${FILE,path= \ "${FILE_LOCATION} \ "}"
请注意反斜杠,空格需要剪掉。