我有从属詹金斯设置。在jenkins的一项工作中,仅当环境变量具有特定值时,才需要通过Editable Email Notification
插件发送电子邮件。因此,我在Execute Shell
命令中设置环境变量的值,如下所示
echo "SHOULD_SEND_EMAIL=$should_send_email" > $WORKSPACE/build/env.properties
在后期制作操作中,我有一个步骤发送带有Script-After Build
触发器的电子邮件,并且触发器脚本如下所示
def workspace = build.getWorkspace()
println "Value of workspace is ${workspace}"
filename = workspace.toString() + "/build/env.properties"
println "Value of filename is ${filename}"
def logs = readFile("${filename}")
println "Value of logs is ${logs}"
但是它在错误以下失败了
15:05:54 Value of workspace is /Users/jenkins/workspace/experiment-job
15:05:54 Value of filename is /Users/jenkins/workspace/experiment-job/build/env.properties
15:05:54 ERROR: Build step failed with exception
15:05:54 groovy.lang.MissingMethodException: No signature of method: Script1.readFile() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl) values: [/Users/jenkins/workspace/experiment-job/build/env.properties]
15:05:54 at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)
15:05:54 at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:81)
15:05:54 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
15:05:54 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
15:05:54 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
15:05:54 at Script1.run(Script1.groovy:7)
15:05:54 at groovy.lang.GroovyShell.evaluate(GroovyShell.java:585)
15:05:54 at groovy.lang.GroovyShell.evaluate(GroovyShell.java:623)
15:05:54 at groovy.lang.GroovyShell.evaluate(GroovyShell.java:594)
15:05:54 at hudson.plugins.emailext.plugins.trigger.AbstractScriptTrigger.trigger(AbstractScriptTrigger.java:55)
15:05:54 at hudson.plugins.emailext.ExtendedEmailPublisher._perform(ExtendedEmailPublisher.java:269)
15:05:54 at hudson.plugins.emailext.ExtendedEmailPublisher.perform(ExtendedEmailPublisher.java:253)
15:05:54 at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
15:05:54 at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
15:05:54 at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:720)
15:05:54 at hudson.model.Build$BuildExecution.cleanUp(Build.java:195)
15:05:54 at hudson.model.Run.execute(Run.java:1788)
15:05:54 at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
15:05:54 at hudson.model.ResourceController.execute(ResourceController.java:98)
15:05:54 at hudson.model.Executor.run(Executor.java:410)
15:05:54 Build step 'Editable Email Notification' marked build as failure
我尝试传递文件的硬编码值,考虑到readFile将从工作空间准备就绪,而不是如下所示的绝对路径
def logs = readFile("/build/env.properties")
println "Value of logs is ${logs}"
但是它仍然在错误以下失败
14:55:32 Value of workspace is /Users/jenkins/workspace/experiment-job
14:55:32 Value of filename is /Users/jenkins/workspace/experiment-job/build/env.properties
14:55:32 ERROR: Build step failed with exception
14:55:32 groovy.lang.MissingMethodException: No signature of method: Script1.readFile() is applicable for argument types: (java.lang.String) values: [build/env.properties]
14:55:32 at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)
14:55:32 at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:81)
14:55:32 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
14:55:32 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
14:55:32 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
14:55:32 at Script1.run(Script1.groovy:7)
14:55:32 at groovy.lang.GroovyShell.evaluate(GroovyShell.java:585)
14:55:32 at groovy.lang.GroovyShell.evaluate(GroovyShell.java:623)
14:55:32 at groovy.lang.GroovyShell.evaluate(GroovyShell.java:594)
14:55:32 at hudson.plugins.emailext.plugins.trigger.AbstractScriptTrigger.trigger(AbstractScriptTrigger.java:55)
14:55:32 at hudson.plugins.emailext.ExtendedEmailPublisher._perform(ExtendedEmailPublisher.java:269)
14:55:32 at hudson.plugins.emailext.ExtendedEmailPublisher.perform(ExtendedEmailPublisher.java:253)
14:55:32 at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
14:55:32 at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
14:55:32 at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:720)
14:55:32 at hudson.model.Build$BuildExecution.cleanUp(Build.java:195)
14:55:32 at hudson.model.Run.execute(Run.java:1788)
14:55:32 at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
14:55:32 at hudson.model.ResourceController.execute(ResourceController.java:98)
14:55:32 at hudson.model.Executor.run(Executor.java:410)
14:55:32 Build step 'Editable Email Notification' marked build as failure
我无法使用https://stackoverflow.com/a/50503979/1465536中提到的File。 有人可以帮助我了解这里的问题吗?如果您有其他根据情况发送电子邮件的解决方案,我也很高兴知道。谢谢。
答案 0 :(得分:0)
该错误提示readFile
的用法错误,请更改为以下内容:
def logs = readFile file: filename