Groovy: Jenkinsfile: Unable to pass argument with space to shell script in jenkins pipeline

784 views Asked by At

I am using a script in my jenkins file and one of the argument passed contains a space (--detect.project.user.groups="DATABASE RELEASE 1.0"):

sh './detect.sh --logging.level.com.synopsys.integration=DEBUG --blackduck.url="${URL}" --blackduck.api.token="${TOKEN}" --detect.project.version.name=${buildVersion} --detect.project.user.groups=\"DATABASE RELEASE 1.0\" --detect.project.name=${projectName}  --detect.source.path="${artifact_dir}/"'

The same script when triggered through regular shell script worked fine and blackduck was able to pick up the user group with the space included but the same command run through jenkinsfile inside scripts with sh, here only DATABASE gets picked up and the scan fails as it is not able to find the correct userGroup.

Let me know if there is any fix to this.

Thanks!

1

There are 1 answers

0
daggett On BEST ANSWER

https://community.synopsys.com/s/document-item?bundleId=integrations-detect&topicId=scripts%2Fscript-escaping-special-characters.html&_LANG=enus

To have literal detect.sh --detect.project.name=\"Project Test\"

You have to escape each backslash with another one in groovy string

sh 'detect.sh --detect.project.name=\\"Project Test\\"'