0

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:

enter image description here

or on the other hand a windows batch script:

enter image description here

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
Rod Kimble
  • 1,302
  • 3
  • 18
  • 44

2 Answers2

2

You want to use print or println statement instead of echo.

See Groovy Plugin for more details.

EDIT: Based on OP's comments about new question following the resolution to the original question.

In order to get the job names, you need to script. For more details refer an existing solution here

Community
  • 1
  • 1
Rao
  • 20,781
  • 11
  • 57
  • 77
  • Thank you. But I get a `groovy.lang.MissingPropertyException: No such property: $jobName for class: Script1` message. Is there something wrong with giving my parameters? – Rod Kimble Mar 22 '17 at 06:19
  • @RodKimble, not really sure, but the exception posted in the question is gone `groovy.lang.MissingMethodException: No signature of method: Script1.echo()`, right? Appreciate if you can accept it answered. – Rao Mar 22 '17 at 06:21
  • The error resulted by one method is gone. But the problem I am suffering and that I want to resolve is still there. – Rod Kimble Mar 22 '17 at 06:23
  • Well, that is what the question is and resolved. The one you are facing can be a new question. Isn't it? By the way, you can refer the edits in the answer. – Rao Mar 22 '17 at 06:25
  • 1
    No. the question is how to print my String value given from my pipeline job to my freestyle job. And this still isnt working – Rod Kimble Mar 22 '17 at 06:28
  • Maybe the description which code belongs to which job was not 100% clear, sorry for that. The call `env.JOB_NAME` in my pipeline jobs script gives me the name of the pipeline job. I want to display this name in my freestyle jobs log. To get the name is not the problem. But I cant access the variable I deliver in my freestyle jobs build call. – Rod Kimble Mar 22 '17 at 06:35
0

Solved the issue. I called the job and gave the string parameters to it but I forgot to parameterize the called job. After parameterizing and defining the parameter names I am able to access them in my second job.

Rod Kimble
  • 1,302
  • 3
  • 18
  • 44