Use a lightweight executor for a declarative pipeline stage (agent none) : <p>I'm using Jenkins Pipeline with the declarative syntax, currently with the following stages:</p>

<ol>
<li>Prepare</li>
<li>Build (two parallel sets of steps)</li>
<li>Test (also two parallel sets of steps)</li>
<li>Ask if/where to deploy</li>
<li>Deploy</li>
</ol>

<p>For steps 1, 2, 3, and 5 I need and agent (an executor) because they do actual work on the workspace. For step 4, I don't need one, and I would like to not block my available executors while waiting for user input. This seem to be referred to as either a "flyweight" or "lightweight" executor for the classic, scripted syntax, but I cannot find any information on how to achieve this with the declarative syntax.</p>

<p>So far I've tried:</p>

<ol>
<li>Setting an agent directly in the pipeline options, and then setting <code>agent none</code> on the stage. This has no effect, and the pipeline runs as normalt, blocking the executor while waiting for input. It is also mentioned in the documentation that it will have no effect, but I thought I'd give it a shot anyway.</li>
<li>Setting <code>agent none</code> in the pipeline options, and then setting an agent for each stage except #4. Unfortunately, but expectedly, this allocates a new workspace for every stage, which in turn requires me to stash and unstash. This is both messy and gives me further problems in the parallel stages (2 and 3) because I cannot have code outside the <code>parallel</code> construct. I assume the parallel steps run in the same workspace, so stashing/unstashing in both would have unfortunate results.</li>
</ol>

<p>Here is an outline of my Jenkinsfile:</p>

<pre><code>pipeline {
    agent {
        label 'build-slave'
    }
    stages {
        stage("Prepare build") {
            steps {
                // ...
            }
        }
        stage("Build") {
            steps {
                parallel(
                    frontend: {
                        // ...
                    },
                    backend: {
                        // ...
                    }
                )
            }
        }
        stage("Test") {
            steps {
                parallel(
                    jslint: {
                        // ...
                    },
                    phpcs: {
                        // ...
                    },
                )
            }
            post {
                // ...
            }
        }
        stage("Select deploy target") {
            steps {
                script {
                    // ... code that determines choiceParameterDefinition based on branch name ...
                    try {
                        timeout(time: 5, unit: 'MINUTES') {
                            deployEnvironment = input message: 'Deploy target', parameters: [choiceParameterDefinition]
                        }
                    } catch(ex) {
                        deployEnvironment = null
                    }
                }
            }
        }
        stage("Deploy") {
            when {
                expression {
                    return binding.variables.get("deployEnvironment")
                }
            }
            steps {
                // ...
            }
        }
    }
    post {
        // ...
    }
}
</code></pre>

<p>Am I missing something here, or is it just not possible in the current version?</p>
