Easiest way to do docker build command within Jenkinsfile running on Jenkins slave node?

Viewed 2460

Basic example of what I want my Jenkinsfile to do:

node {
   sh 'docker build -t foo/bar .'
}

It seems like I need to install docker onto the Jenkins slave image that's executing my Jenkinsfile. Is there an easy way of doing this? (That Jenkins slave image is itself a docker container)

Are my assumptions correct?

  1. When running with Jenkins master/slaves, the Jenkinsfile is executed by a Jenkins slave
  2. Jenkins plugins installed via the Manage Plugins section (e.g. the Docker Plugin, or Gcloud SDK plugin) are only installed on the Jenkins masters, therefore I would need to manually build my Jenkins slave docker image and install docker on the image?

Since I also need access to the 'gcloud' command (I'm running Jenkins via Kubernetes Helm/Charts), I've been using the gcr.io/cloud-solutions-images/jenkins-k8s-slave image for my Jenkins slave.

Currently it errors out saying "docker: not found"

1 Answers
Related