Docker slave plugin quick start

Overview

 

This plugin allows to execute a jenkins job inside a (set of) container(s). Jenkins job run into slave containers which linked between each other. Jenkins uses own mechanism to control build on slaves(docker slave containers). Jenkins connects to docker API (socket in our case) and API allows to control remote processes as well. 

 

Workflow

Benefits

  • Docker offer isolated, customizable environment
  • We can use any image, without jenkins specific requirement 
  • Compose your build like a docker-compose, linking your main container with side container(selenium for example or database) 
  • Support pipelines
  • Can be used your Dockerfile in SCM (docker as a code)

 

How to configure Docker slaves plugin

  • Install plugin. Manage Jenkins – Manage plugins – Available – Find “Docker slaves plugin”
  • Manage Jenkins – Configure system 

     

 

 Remoting image – jenkinsci/slave strongly recommended 

Docker host URI – docker socket on the Jenkins host

 

  •  Access to socket for Jenkins user

 

On the Jenkins host type following command in bash

 

 

Check permissions

 

 

 

Output can be something like this

 

 

 

Check if everything is fine with docker API and user Jenkins

 

 

 

If you see something like “Can’t connect to Docker API” that something was wrong adn you have to check permission of socket or make sure docker daemon is up and running.

 

If you see like a list of containers it means that everything is ok and you can create job. 

 

How to create Job with Docker slaves plugin

Create Job – Freestyle project

Choose “Run the build inside Docker containers”.  In test case I used image – maven:3.3.3-jdk-8 and side container with image – selenium/standalone-firefox.

 

Choose SCM – Git and define repo with test project

Define build step “Execute shell” and command mvn clean test 

Eventually! You can run the Job. 

Enjoy and see output!

Добавить комментарий

Ваш e-mail не будет опубликован. Обязательные поля помечены *