Passing parameters to script commands from Jankins pipeline

Hello,
My first post here, so Hi to the Jenkins community :slight_smile:
I’ve been using Jenkins quite a lot and normally manage to find my way, but every now and then things get quite tricky, so here’s what I’m struggling with.

When trying to execute cucumber tests from Jenkins pipeline with the invocation looking like this:

sh '''mvn spring-boot:start \
                            exec:java \
                            -Dexec.classpathScope=test \
                            -Dexec.mainClass=io.cucumber.core.cli.Main \
                            -Dexec.args=\\"src/test-bdd/resources/features/set02 --glue gluepackage\\" \
                            spring-boot:stop
                        '''

after that line gets invoked, Jenkins will output the following:

20:39:31  + mvn spring-boot:start exec:java -Dexec.classpathScope=test -Dexec.mainClass=io.cucumber.core.cli.Main -Dexec.args="src/test-bdd/resources/features/set02 --glue gluepackage" spring-boot:stop
20:39:31  Unable to parse command line options: Unrecognized option: --glue
20:39:31  
20:39:31  usage: mvn [options] [<goal(s)>] [<phase(s)>]

That basically means the shell is not passing the value of the -Dexec.args parameter as a string to the exec plugin but rather interprets that value as arguments to the mvn command. Obviously there’s no –glue argument maven recognises, so the shell will print help on how to use maven and exit with a an error.

If I copy-paste the generated command into my terminal in the project directory and hit enter, it will run perfectly fine meaning the contents between quotes will be passed to the exec:java plugin command and the cucumber tests start and run as they should.

I tried quite a few things (single quotes, double quotes, groovy style string interpolation, passing as environment variable etc) except probably writing a simple shell script and invoking the command line inside it with params passed to the script which would probably be the closest to what happens when invoked directly from command line, but from all that I have tried nothing seems to work.

I am running Jenkins 2.375.2. Both controller and nodes run on Mac.

Will appreciate any suggestions.

I don’t think you need to escape the quotes, i don’t know though.