title: Jenkins is re-using a pipeline workspace and I wish for each build to have a unique workspace
body: <p>So, most of the questions and answers I've found on this subject is for people who want to use the SAME workspace for different runs.  (Which baffles me, but then I require a clean slate each time I start a job.  Leftover stuff will only break things) </p>
  
  <p>My issue is the EXACT opposite - I <em>MUST</em> have a separate workspace for each run (or I need to know how to create files with the same name in different runs that stay with that run only, and which are easily reachable from bash scripts started by the pipeline!)</p>
  
  <p>So, my question is - how do I either force Jenkins to NOT use the same workspace for two concurrently-running jobs on different hosts, OR what variable can I use in the 'custom workspace' field to accomplish this?</p>
  
  <p>After I responded to the question by @Joerg S I realized that I'm saying the thing that Joerg S says CAN'T happen is EXACTLY what I'm observing!  Jenkins is using the SAME workspace for 2 different, concurrent, jobs on 2 different hosts.  <strong>Is this a Jenkins pipeline bug?</strong></p>
  
  <p>See below for a bewildering amount of information.</p>
  
  <p>Given the way I have to go onto and off of nodes during the run, I've found that I can start 2 different builds on different hosts of the same job, and they SHARE the workspace dir!  Since each job has shell scripts which are busy writing files into that directory, this is extremely bad.</p>
  
  <p>In <a href="https://stackoverflow.com/questions/20537137/custom-workspace-in-jenkins">Custom workspace in jenkins</a> we are told to use custom workspace, and I'm set up just like that</p>
  
  <p>In <a href="https://stackoverflow.com/questions/35207067/jenkins-how-to-run-builds-in-unique-directories">Jenkins: how to run builds in unique directories</a> we are told to use ${BUILD_NUMBER} in the above custom workspace field, so what I tried was:</p>
  
  <pre><code> ${JENKINS_HOME}/workspace/${ITEM_FULLNAME}/${BUILD_NUMBER}
  </code></pre>
  
  <p>All that happens to me when I use that is that the workspace name is, you guessed it, "${BUILD_NUMBER}" (and I even got a "${BUILD_NUMBER}@2" just for good measure!)</p>
  
  <p>I tried {$BUILD_ID}, same thing (uses that literally, does not substitute the number).</p>
  
  <p>I have the 'allow concurrent builds' turned on.</p>
  
  <p>I'm using pipelines exclusively.</p>
  
  <p>All jobs here, as part of normal execution, cause the slave, non-master host to reboot into an OS that does not have the capability to run slave.jar (indeed, it has no network access at all), so I cannot run the entire pipeline on that host.</p>
  
  <p>All jobs use the following construct somewhere inside them:</p>
  
  <pre><code>    tests=Arrays.asList(tests.split("\\r?\n"))
      shellerror=231
      for( line in tests){
  </code></pre>
  
  <p>So let's call an example job 'foo' that loops through a list, as above, that I want to run on 2 different hosts.  The pipeline for that job starts running on master (since the above <strong>for (line in tests)</strong> is REQUIRED to run on a node!)). Then goes back and forth between master and slave, often multiple times.</p>
  
  <p>If I start this job on host A and host B at about the same time, they will BOTH use the workspace ${JENKINS_HOME}/workspace/${JOB_NAME}, or in my case /var/lib/jenkins/jenkins/workspace/job</p>
  
  <p>Since they write different data to files with the same name in that directory, I'm clearly totally broken immediately.</p>
  
  <p>So, how do I force Jenkins to use a unique workspace EVERY SINGLE JOB?</p>
  
  <p>Or, what???</p>
  
  <p>Other things: pipeline build step version 2.5.1, Jenkins 2.46.2</p>
  
  <p>I've been trying to get the workspace statement ('ws') to work, but that doesn't quite work as I expected either - some files are in the workspace I explicitly name, and some are still in the 'built-in' workspace (workspace/).</p>
  
  <p> I was asked to provide code.  The 'standard' pipeline I use is about 26K bytes, composing about 590 lines.  So, I'm going to GREATLY reduce.  That being said:</p>
  
  <pre><code>node("master") { // 1
     ..... lots of stuff....
  }  // this matches the "node('master')" above
  node(HOST) {
    echo "on $HOST, check what os"
    if (isUnix()) 
        ...some more stuff...
  } // end of 'node(HOST)' above
  if (isok == 0 ) {
     node("master") { 
        echo "----------------- Running on MASTER 19 $shellerror waiting on boot out of windows ------------"
        sleep 120
        echo "----------------- Leaving MASTER ------------"
     }
  }
   ... lots 'o code ...
  
  node(HOST) {
    ... etc 
  } // matches the latest 'node HOST' above
  node("master") { // 120
      .... code ...
      for( line in tests) {
          ...code...
      }
  }
  ... and on and on and on, switching back and forth from one to the other
  </code></pre>
  
  <p>FWIW, when I tried to make the above use 'ws' so that I could make certain the ws name was unique, I simply added a 'ws wsname' block directly under (almost) every 'node' opening so it was </p>
  
  <pre><code>node(name) { ws (wsname) { ..stuff that was in node block before... } }
  </code></pre>
  
  <p>But then I've got two directories to worry about checking - both the 'default' workspace/jobname dir AND the new wsname one.  </p>