title: How to copy an artefact from one agent to another in a Jenkins declarative pipeline?
body: <p>I'd like to use a Jenkins declarative pipeline and the agent syntax to build an artefact that I want to then deploy to a side car container, as illustrated in this pseudo-code:</p>
  
  <pre><code>pipeline {
      agent none 
      stages {
          stage('Build Artefact') {
              agent { docker 'build-agent' } 
              steps {
                  &lt; I want to create the artefact to deploy to a side car container here &gt;
              }
          }
          stage('Deploy Artefact') {
              agent { docker 'side-car' } 
              steps {
                  &lt; I want to deploy the artefact created in the previous stage here &gt;
              }
          }
      }
  }
  </code></pre>
  
  <p>What I am struggling with is working out how to pass a file from the container used by the 'Build Artefact' stage to the container used in the 'Deploy Artefact', as far as I am aware <code>stash</code> will not work across containers, unless anyone has experience otherwise.</p>
  
  <p>According to the Jenkins documentation, you can use the args argument to specify a volumes for the declarative pipeline syntax:</p>
  
  <pre><code>pipeline {
      agent {
          docker {
              image 'maven:3-alpine'
              args '-v $HOME/.m2:/root/.m2'
          }
      }
      stages {
          stage('Build') {
              steps {
                  sh 'mvn -B'
              }
          }
      }
  }
  </code></pre>
  
  <p>However, I'm wondering if there is a more elegant solution that does not involve passing volumes around.</p>