How to run one Jenkins stage on a different agent

Viewed 1243

I have a Jenkinsfile with a bunch of stages. Agent is defined at top level like so:

agent {
    label 'windows'
}

There are a pool of agents labelled windows. I'd like to make one of the parallel stages to run on a different agent that the whole pipeline, but from the same agent windows pool.

Not sure if I should use Lockable Resources plugin or agent{} option can be used in some way.

Any suggestions are appreciated!

1 Answers

Might be not very optimal solution, but it should allow you to split the build to different nodes.

agent can be used on pipeline level, as well as on stage level.

You can introduce two labels (I assume that you have two stages running in parallel) e.g. windows-pool-1 and windows-pool-2 and make sure all your windows are split to this two groups. Then just use different pools for these stages and those will run on different machines guaranteed.

There's even an example in official documentation (here's a bit shorter adjusted version):

pipeline {
    agent 'windows'
    stages {
        stage('Parallel Stage') {
            parallel {
                stage('Run on pool 1') {
                    agent {
                        label "windows-pool-1"
                    }
                    steps {
                        echo "do stuff on 1"
                    }
                }
                stage('Run on pool 2') {
                    agent {
                        label "windows-pool-2"
                    }
                    steps {
                        echo "do stuff on 2"
                    }
                }
            }
        }
    }
}
Related