Maven param that contains spaces in jenkins declarative pipeline

435 Views Asked by At

Let's say that we have a jenkins pipeline that at some point we execute a maven parameterized build:

sh "mvn clean install -DparameterType=${parameter}"

What if the parameter's value contained spaces? Eg the value was "test param".

When running on IDE, this of course works:

mvn clean install -DparameterType="test param"

But if we do sth similar inside the pipeline, like

sh "mvn clean install -DparameterType=\"${parameter}\""

or

sh "mvn clean install -DparameterType=""${parameter}""

it doesn't and the param is passed like

-DparameterType=test param

which is not good for maven. Any ideas please?

1

There are 1 best solutions below

2
On

You can try using:

 sh """
 mvn clean install -DparameterType=\"${parameter}\"
 """