title: Jenkins agent none VS labels - block execution on delegated step
body: <p>I have 2 workers, but only one of them has proper 'build stack' (should be used for build only), so I'd like to 'delegate' one step of my pipeline to that node. Build happens only on 'develop' branch, so other Jobs in that repo should execute on the 'remaining' available node.</p>
  <p>If I use the label '<strong>builder</strong>' in the stage, I get a very strange behavior...</p>
  <p><strong>Scenario A</strong></p>
  <p>Job is running on a <strong>node2</strong> - and waits indefinitely for a free worker - as it does not understand that <strong>builder</strong> is the same node as a <strong>node2</strong></p>
  <p><em>Waiting for next available executor on 'builder'</em></p>
  <p><strong>Scenario B</strong></p>
  <p>Job is running on a <strong>node1</strong>, and is delegated to <strong>builder (node2)</strong> - but it <strong>blocks</strong> both nodes, other jobs that could meanwhile execute on node1, are waiting in the queue...</p>
  <p>also, step xxxx is waiting indefinitely</p>
  <p><em>Waiting for next available executor on 'node1'</em> (like it could not return to itself).</p>
  <p>Any idea what could be a workaround?</p>
  <p>I know this is not a common practice to delegate one step to some external node, but to me a behavior where node2 and builder labels are not mapped as the same worker, seems to be a <strong>bug</strong>...</p>
  <p>I know that for a docker-based agent there is a flag <strong>reuseNode</strong> that in a way would be what I want :D</p>
  <p>And for a delegation... well I wish it would not block Job execution on the node1 until the builder is finished... this seems wired to me as well..</p>
  <p>2 workers with labels</p>
  <ul>
  <li>node1, deployer</li>
  <li>node2, builder</li>
  </ul>
  <pre><code>pipeline {
      //agent none
      //agent { label 'node1' } - preferred node for most of the steps
      agent { label 'node1 || node2' }
      stages {
          stage(&quot;Prepare build&quot;) {
              agent { label 'node2 || builder' }
              when { branch 'develop'}
              steps {
                  echo &quot;prepare build&quot;
              }
          }
          stage(&quot;Build&quot;) {
              agent { label 'builder' }
              when { branch 'develop'}
              steps {
                  sh &quot;echo do build&quot;
              }
          }
          stage(&quot;Test&quot;) {
              agent { label 'node1 || node2' }
              steps {
                  sh &quot;echo do test, other things ... &quot;
              }
          }
          stage(&quot;xxxx&quot;) {        
              agent { label 'node1' }
              steps {
                  sh &quot;xxxx&quot;
              }
          }
      }
    post {
      failure {
        sh &quot;echo do something, cleanup.sh&quot;
      }
  }
  </code></pre>
  <p>If I use <strong>agent none</strong>, NONE of my stages are executed, and the post triggers, with an error<br />
  <em>ERROR: Attempted to execute a step that requires a node context while agent none was specified. Be sure to specify your own node { ... } blocks when using agent none.</em></p>
  <p>I <strong>could</strong> add a <code>node {}</code> section to the post step, but since the previous steps are skipped (I believe the git repo is not properly pulled) it is failing anyway even with the node{} due to file missing (cleanup script).</p>