Search code examples
dockerjenkinsjenkins-pipeline

how docker agent is selected in slave node in jenkins


in Jenkinsfile below, agent docker is used https://www.jenkins.io/doc/book/pipeline/docker/

But which slave is used, can I point to the VM I want to run docker?

pipeline {
    agent {
        docker { image 'node:14-alpine' }
    }
    stages {
        stage('Test') {
            steps {
                sh 'node --version'
            }
        }
    }
}

Something like

agent {
    label "dockerserver"
    docker { image 'node:14-alpine' }
}

Solution

  • Jenkins assumes any configured agent can run docker containers. This is documented here: https://www.jenkins.io/doc/book/pipeline/docker/#specifying-a-docker-label

    A label can be configured in the System Configuration to select which agents can run containers:

    Pipeline provides a global option in the Manage Jenkins page, and on the Folder level, for specifying which agents (by Label) to use for running Docker-based Pipelines.

    enter image description here

    Attach the label to the agents which should run docker containers.