Answers: <p>If the input string is failing due to folders with spaces not having quotes around them, try adding quotes around every object.</p>
  <p>The InpFolderList already adds end quotes:</p>
  <p><code>InpFoldersList=&quot;\&quot;$inpFoldersList&quot;\&quot;</code></p>
  <p>Add the quotes around every object.</p>
  <p><strong>groovy:</strong></p>
  <pre><code>class Example { 
     static void main(String[] args) { 
          String FolderList = &quot;test1,test2,test3,Folder name1,Folder name2,Folder name3&quot;;
          println(FolderList.replaceAll(&quot;,&quot;,&quot;\&quot;,\&quot;&quot;));
     } 
  }
  </code></pre>
  <p><strong>Output:</strong> (End quotes are left off)</p>
  <p><code>test1&quot;,&quot;test2&quot;,&quot;test3&quot;,&quot;Folder name1&quot;,&quot;Folder name2&quot;,&quot;Folder name3</code></p>
  <p><strong>Test Code:</strong> <a href="https://www.jdoodle.com/execute-groovy-online/" rel="nofollow noreferrer">https://www.jdoodle.com/execute-groovy-online/</a> (Copy / Paste Code and Execute)</p>
  <p>Using above as an example, you could also add the end quotes and have a complete String variable to pass as $InpFoldersList, which would remove confusion if attempting to debug.</p>
  <p><strong>Reference:</strong> <a href="http://docs.groovy-lang.org/latest/html/api/org/codehaus/groovy/runtime/StringGroovyMethods.html#replaceAll(java.lang.CharSequence,java.util.regex.Pattern,java.lang.CharSequence)" rel="nofollow noreferrer">http://docs.groovy-lang.org/latest/html/api/org/codehaus/groovy/runtime/StringGroovyMethods.html#replaceAll(java.lang.CharSequence,java.util.regex.Pattern,java.lang.CharSequence)</a></p>
  
Answers: CC BY-SA 4.0
Answers: 2020-08-09T13:46:49.440Z
Answers: 2020-08-09T13:46:49.440Z
Answers: George
Answers: <p>What about save the env variable within a file and read from it after, you can encrypt/decrypt or use another type of parameter if that is a problem.</p>
  
Answers: CC BY-SA 4.0
Answers: 2020-05-26T14:06:13.457Z
Answers: 2020-05-26T14:06:13.457Z
Answers: anVzdGFub3RoZXJodW1hbg
Body: <p>In jenkins Job, I am taking a String parameter as below: </p>
  
  <p>FoldersList = test1,test2,test3,Folder name1,Folder name2,Folder name3 </p>
  
  <p>when I pass this value to environment variable the jenkins job fails with error : Unknown lifecycle phase etc etc since spaces are not allowed in folder names. </p>
  
  <p>I am passing the environment variable like this in goals and options section : </p>
  
  <p>exec:java -Dexec.classpathScope="test" -Dexec.mainClass="com.mypackage.main.TestNGRunner" -Dexec.cleanupDaemonThreads=false "-Dexec.args=-inputexcel=Data.xlsx -jenkinsJobName=testJob
   -layer=MultiplefolderTest -InpFoldersList="\"$inpFoldersList"\" -threadCount=12 -retryCount=3"</p>
  
  <p>If I pass a single string within double quotes it works but the user will enter multiple folder names possibly with spaces. Please can somebody help since I tried different options but none work. Is there a way to manipulate the string and pass it to the environment variable. </p>
  
Tags: <jenkins>
Title: How to pass a String parameter with spaces in Jenkins to environment variable
UserDisplayName: shanmuki
ThreadText: # How to pass a String parameter with spaces in Jenkins to environment variable
  
  (Asked by: username_0 on 2020-05-24)
  
  In jenkins Job, I am taking a String parameter as below:
  
  FoldersList = test1,test2,test3,Folder name1,Folder name2,Folder name3
  
  when I pass this value to environment variable the jenkins job fails with error : Unknown lifecycle phase etc etc since spaces are not allowed in folder names.
  
  I am passing the environment variable like this in goals and options section :
  
  exec:java -Dexec.classpathScope="test" -Dexec.mainClass="com.mypackage.main.TestNGRunner" -Dexec.cleanupDaemonThreads=false "-Dexec.args=-inputexcel=Data.xlsx -jenkinsJobName=testJob
  -layer=MultiplefolderTest -InpFoldersList="\"$inpFoldersList"\" -threadCount=12 -retryCount=3"
  
  If I pass a single string within double quotes it works but the user will enter multiple folder names possibly with spaces. Please can somebody help since I tried different options but none work. Is there a way to manipulate the string and pass it to the environment variable.
  
  **Tags:** jenkins
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2020-08-09. Score: 1
  
  If the input string is failing due to folders with spaces not having quotes around them, try adding quotes around every object.
  
  The InpFolderList already adds end quotes:
  
  `InpFoldersList="\"$inpFoldersList"\"`
  
  Add the quotes around every object.
  
  **groovy:**
  
  ```
  class Example { 
     static void main(String[] args) { 
          String FolderList = "test1,test2,test3,Folder name1,Folder name2,Folder name3";
          println(FolderList.replaceAll(",","\",\""));
     } 
  }
  
  ```
  
  **Output:** (End quotes are left off)
  
  `test1","test2","test3","Folder name1","Folder name2","Folder name3`
  
  **Test Code:** <https://www.jdoodle.com/execute-groovy-online/> (Copy / Paste Code and Execute)
  
  Using above as an example, you could also add the end quotes and have a complete String variable to pass as $InpFoldersList, which would remove confusion if attempting to debug.
  
  **Reference:** <http://docs.groovy-lang.org/latest/html/api/org/codehaus/groovy/runtime/StringGroovyMethods.html#replaceAll(java.lang.CharSequence,java.util.regex.Pattern,java.lang.CharSequence)>
  
  
  ---
  
  ### Answer by username_2 on 2020-05-26. Score: 0
  
  What about save the env variable within a file and read from it after, you can encrypt/decrypt or use another type of parameter if that is a problem.
  
  
  ---
  
  