Pipeline - I would like to use Docker CLI inside of a Pipeline job

Issue

I would like to use Docker CLI inside of a Pipeline job

Environment

  • CloudBees Jenkins Enterprise
  • Pipeline Docker Plugin

Resolution

Wrapping the section you want to use docker in with docker.withTool("default") {} will allow you to use the docker command line tool. This will install docker on that slave to have it running as a service. You need to make sure that “default” points to a docker tool inside of Manage Jenkins> Configure System which will also run on the os of the slave.

Your pipeline script will go from this(which doesnt work unless you have docker installed on the slave):

withDockerServer([credentialsId: "AWS-Jenkins-Build-Slave", uri: "tcp://54.229.21.138:2376"]) { 

sh "printenv" 
sh "docker images" 
base = docker.build("flyvictor/victor-wp-build") 
base.push("tmp-fromjenkins") 
}

To this(which does work):

docker.withTool("default") { 

withDockerServer([credentialsId: "AWS-Jenkins-Build-Slave", uri: "tcp://54.229.21.138:2376"]) { 

sh "printenv" 
sh "docker images" 
base = docker.build("flyvictor/victor-wp-build") 
base.push("tmp-fromjenkins") 
} 
}
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.