MKK
MKK

Reputation: 3

escaping special character in groovy

I want to run my command in background.And I am trying this in jenkins pipeline This is my command

sh "./node_modules/.bin/selenium-standalone start \&"

But when I run this command & gets single quote because of which the command fails. OUTPUT : ./node_modules/.bin/selenium-standalone start '&'

Can anyone suggest how I should escape the & in groovy so I just get & without single quote.

Upvotes: 0

Views: 2210

Answers (2)

MaratC
MaratC

Reputation: 6889

This won't work that easily, first because & is a command for job control in the interactive shell, and also because of how process trees work in Linux.

To make a long story short, if you need to start a command in background, you should use daemonize:

sh label: "starting selenium in the background",
    script: "/usr/local/bin/daemonize ./node_modules/.bin/selenium-standalone start"

Upvotes: 3

cfrick
cfrick

Reputation: 37063

& is no special character to Groovy. It is for the shell. So if you dont want to start this command in the background but want to pass & as an argument to your script there, you have to use \\& inside "-strings. And if you want to start the script in the background, then just use &.

Upvotes: 1

Related Questions