6

I'm pretty new to groovy and jenkins pipelines. I'm trying to launch a python command line application from jenkins pipeline in shell command , but my build fails since one of the arguments uses pipe(|) symbol and pipeline interprets and adds single quotes to the command.

Below is my pipeline where I'm passing TAGS as jenkins build parameters where value is given as "test1|test2"

pipeline {
    echo "${TAGS}"
        stage('Shoot tests') {

 stage('Shoot tests') {
            echo "${TAGS}"
            echo "-tags=\\\"${TAGS}\\\""
            echo "-tags=\"${TAGS}\""
            sh "python /orchestrator.py -server=${SERVER_URL} -tags=\"${TAGS}\" -output-dir=${output_base} || true" 
        }

}

Console prints as below:

[Pipeline] stage
[Pipeline] { (Shoot tests)
[Pipeline] echo
14:57:51  "test1|test2"
[Pipeline] echo
14:57:51  -tags=\""test1|test2"\"
[Pipeline] echo
14:57:51  -tags=""test1|test2""
[Pipeline] sh
14:57:51  + python /orchestrator.py -server=https://test.net '-tags="test1|test2"' -output-dir=outputs

Could you help me in how to avoid the single quote(' ') around the -tags argument ??

I want the command to be like this

python /orchestrator.py -server=https://test.net -tags="test1|test2" -output-dir=outputs

currently it's coming as

python /orchestrator.py -server=https://test.net '-tags="test1|test2"' -output-dir=outputs

Anonymous
  • 71
  • 4
  • Info : I tried with -tags=\${TAGS} in the command , the result is still the same. – Anonymous Sep 20 '19 at 09:46
  • `echo "-tags='${TAGS}'"`? – tim_yates Sep 20 '19 at 11:07
  • 1
    Your sh step looks good. You can change `sh` to `echo` to print out it ,then you can check it's as expect or not . – yong Sep 20 '19 at 13:43
  • Agree that this behavior looks unusual. Your `SERVER_URL` variable string assignment is not something with weird formatting or anything is it? – Matthew Schuchard Sep 20 '19 at 13:54
  • 1
    Similar problem here. I have a variable which contains a file path with spaces. I want to use it in a shell command so it needs quotes around it. Nothing works, mostly because of the extra single quotes you've pointed out. I can get `echo` to output what I want but `sh` of the same string has the extra single quotes which break everything. – Carl Nov 21 '19 at 16:08
  • @Anonymous did you manage to solve this issue? – latata Oct 09 '20 at 11:44
  • I suspect the above problem is not a Jenkins problem. It's related to https://stackoverflow.com/questions/6087494/bash-inserting-quotes-into-string-before-execution – Henrik Dec 17 '20 at 08:54

0 Answers0