简体   繁体   中英

Run job inside docker container in specific agent Jenkins

I am trying to run the Jenkins pipeline steps in the Docker container in a specific agent. I could use docker to run it but the container will run in a random agent but i need it to run in specific agent.

Here's what i tried:

pipeline {
    agent { label 'agent-007' }

    stages {            
        stage("Unit Tests") {
          agent { docker 'image-name' }
          steps {
            sh 'pwd'
            sh 'hostname'
          }
        }
    }
    
}

In the documentation Specifying a Docker Label it says that in the configuration for your Jenkins job, you can specify which agent you want docker to run on. In your case, you could set "Docker Label" to "agent-007" in your job configuration. You can also specify which docker registry you want to pull from which is really handy if you use Artifactory, for instance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM