KBEC-00490 - Textarea Parameter May Break Your Code

Article ID:4402593625499
1 minute readKnowledge base
On this page

Problem

You have a procedure with a parameter of type "textarea". A step which uses the parameter sometimes fails with:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/tmp/ecmdrAgent/agent.C3WA7LDJE25AFCTA.run-0932b0fa-6264-11ea-b4d7-06d0621b793d-0945eaa6-6264-11ea-aa90-06d0621b793d.cmd: 1: expecting anything but ''\n''; got it anyway @ line 1, column 15.
println "line1
^

1 error

Solution

This error tells that there is an error in the groovy code in the step command. But this looks impossible as the step command contains only one line:

println "$[input-paramater]"

According to Using property values:

=== Using property values

A job step can access a property value by two methods. The first method is substitution, using the $[ ] notation. Suppose you enter the following text as a command for a step:

make PLATFORM=$[platform]

Before running the step, CloudBees CD/RO finds the property named platform and substitutes its value in the command string in place of $[platform]. For example, if the property contains the value windows, the actual command executed is:

make PLATFORM=windows

The substitution method can be used for a command in a step and for any step fields, such as the resource or working directory. This method allows you to compute configuration information in an early step of a job, then use that configuration information to control later steps in the job.

So the above code only works when the value of "input-paramater" does NOT contain a carriage return. It fails with the error shown at the start of the article when the value of "input-paramater" includes multiple lines.

When using "textarea" parameter in groovy, Groovy Multiline String is helpful. The following code works fine:

def parameterSstring = '''
$[input-paramater]
'''
println parameterSstring
This article is part of our Knowledge Base and is provided for guidance-based purposes only. The solutions or workarounds described here are not officially supported by CloudBees and may not be applicable in all environments. Use at your own discretion, and test changes in a safe environment before applying them to production systems.