The easiest way to execute a docker build command in a Jenkins file running on a Jenkins node slave?

A basic example of what I want to do with my Jenkins file:

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

It seems I need to install dockers on the slave Jenkins image that my Jenkinsfile is executing. Is there an easy way to do this? (This slave Jenkins image is itself a docker container)

Are my assumptions correct?

  • When working with a Jenkins master / slave, the Jenkins file is executed by a Jenkins subordinate
  • Jenkins plugins installed through the "Manage plugins" section (for example, Docker Plugin or Gcloud SDK plugin) are installed only on Jenkins wizards, so will I need to manually create an image of Jenkins dockers and install dockers on the image?

Since I also need access to the gcloud command (I run Jenkins through Kubernetes Helm / Charts), I used the image gcr.io/cloud-solutions-images/jenkins-k8s-slavefor my Jenkins subordinate.

He is currently mistaken in saying "docker: not found"

+4
source share
1 answer

My guess is that you want docker buildinside a Jenkins subordinate (which is a Kubernetes module, I assume Kubernetes Jenkins Plugin was created )

, Kubernetes pod, Jenkins, , node, Kubernetes ( , ).

, Docker gcr.io/cloud-solutions-images/jenkins-k8s-slave, , , Jenkins JNLP Slave, , Docker!

:

, Jenkins:

enter image description here

, ( , ), Docker .

  • , , JNLP, Docker. , , Jenkins Docker , , . , , JNLP .

Jenkins Plugin

enter image description here

, JNLP , . , Docker Docker.

, JenLink JNLP .

, , Jenkins, Kubernetes .

:

, Radu M

+3

Source: https://habr.com/ru/post/1682976/


All Articles