0
votes

How to ensure a stage is executed in a flyweight Jenkins executor?

Suppose I have the following Jenkinsfile:

pipeline {
    agent any
    stages {
        stage("Build") {
            // build
        }
        stage("Review") {
            agent none
            steps {
                input "Deploy to production?"
            }
        }
        stage("Promotion") {
            steps {
                echo "Promotion"
            }
        }
    }
}

In the stage Review I designated agent none, which, to my understanding, means that Jenkins would use a flyweight executor for this stage. But still, the executor is heavyweight during the stage and uses up one of the valuable executors on the Jenkins slave.

Is there are setting on Jenkins that could potentially disable leightweight executors? Is there a plugin that enables lightweight executors? Is my Jenkinsfile flawed?

1
As far as I understand the documentation jenkins.io/doc/book/pipeline/syntax the ‘agent any’ clause will allocate an agent globally for executing the pipeline. You’ll need to say ‘agent none’ there and in turn specifically assign agents in the stages which will Requiem agent.Joerg S
Thanks @JoergS You are correct.Sebastian Häni

1 Answers

0
votes

You have to use agent none at the start to enable flyweight executors.

pipeline {
    agent none
    stages {
        stage("Build") {
            agent any
            steps {
                // build
            }
        }
    }
}

But doing this will limit what you can do in the setup blocks like environment since there is no real machine available outside the stages. This might mean that a lot of the pipeline has to be rewritten if you didn't start out using agent none.