I want to print some data from my pipeline job to my freestyle job log. Therefore in my pipeline job I call the job and give some parameters:
mailBody = buf.toString()
build job: 'sendEmail', parameters:
[
string(name: 'jobName', value:env.JOB_NAME),
string(name: 'buildNumber', value: env.BUILD_NUMBER),
string(name: 'mailBody', value: mailBody)
]
Inside my Freestyle job sendEmail
I have two options. On the one hand I can call a system groovy script
:
or on the other hand a windows batch
script:
But both of those possibilities are not working. The batch call doesnt recognize the variable and prints env.JOB_NAME
and not the value of this variable.
The groovy script results in the following error:
groovy.lang.MissingMethodException: No signature of method: Script1.echo() is applicable for argument types: (java.lang.String) values: [test]
Possible solutions: each(groovy.lang.Closure), getAt(java.lang.String), wait(), run(), run(), find()
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:81)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
at Script1.run(Script1.groovy:1)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:663)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:650)
at hudson.plugins.groovy.SystemGroovy.run(SystemGroovy.java:118)
at hudson.plugins.groovy.SystemGroovy.perform(SystemGroovy.java:74)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
at hudson.model.Build$BuildExecution.build(Build.java:205)
at hudson.model.Build$BuildExecution.doRun(Build.java:162)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:534)
at hudson.model.Run.execute(Run.java:1728)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:404)
EDIT: After changing echo
to println
I am able to display values in my freestyle jobs build. But there seems to be something wrong in giving my parameters. The commmand println $CHANGE_AUTHOR_EMAIL
, println $jobName
, println $buildNumber
and println $mailBody
are resulting in the follwoing error:
groovy.lang.MissingPropertyException: No such property: $jobName for class: Script1