I am trying to setup sh command as part of my Jenkins pipeline. This command has one parameter where list of values is supplied. Those values have spaces in them.I have tried so many things, arrays, escaping etc etc none worked. Here is an example:# In Jenkins task I configure env variable:VALUE_LIST=(Value One Value Two Value Three)# In pipeline:...sh command --param ${env.VALUE_LIST[@]}...Please understand that this is only one of the ways I tried to make this work. I need the result command to look like:command --param Value One Value Two Value ThreeBest I could achieve wascommand --param Value One Value Two Value ThreeWhich obviously does not work
Jenkins pipelines, sh, quotes and spaces
bash;shell;string;jenkins
This should work.printf %s\0 ${VALUE_LIST[@]} | xargs -0  sh -c 'command --param $@' command_namePrint the values to xargs and use null as delimiter. Then xargs calls sh and sh executes the command with the values as arguments. The last piece, command_name, will represent the command by the name you provide. It is obligatory in this construct, as otherwise command will not receive the first value form the list $@.