Run Jenkins master and slave with Docker
Asked Answered
P

2

6

I want to setup Jenkins master on server A and slave on server B with use of Docker.

Both servers are virtual machines dedicated for Jenkins.

Currently I have started Docker container on server A for master, based on the official Jenkins docker image. But what docker image should I use for Jenkins slave?

Pane answered 24/9, 2016 at 22:2 Comment(1)
I would suggest you set up jenkins slave first without the Docker part, so you better understand what a Jenkins slave actually is. Then you can create a container to run the slave in.Akerboom
H
5

That actually depends on the environment and tools you need in your build environment. For example, if you build a C project, you would need an image containing a C compiler and possibly make if you use Makefiles. If you build a Java project, you would need a JDK with a Java compiler and possibly Ant / Maven / Gradle if you use them as part of your build.

You can use the evarga/jenkins-slave as a good starting point for your build slave.

This image already contains JDK. If you simply need JDK and Maven on your build slave, you can build your Docker image with the following Dockerfile:

FROM evarga/jenkins-slave

run apt-get install maven

Using Docker images for build slaves is actually a good idea. Some of the reasons appear at Templating Jenkins Build Environments with Docker Containers:

Docker has established itself as a popular and convenient way to bootstrap isolated and reproducible environments, which enables Docker containers to be the most maintainable slave environments. Docker containers’ tooling and other configurations can be version controlled in an environment definition called a Dockerfile, and Dockerfiles allows multiple identical containers can be created quickly using this definition or for more customized off-shoots to be created by using that Dockerfile’s image as a base.

Hill answered 25/9, 2016 at 7:10 Comment(4)
So basically I need simple docker image with only JDK and Maven installed (since my source code use it to build) and ssh enabled use it as Jenkins slavePane
@IsmarSlomic - Yes. Since evarga/jenkins-slave already contains JDK, you can create an image base on it for the JDK and Jenkins configuration and add Maven. See the sample Dockerfile in my edited answer.Hill
Thanks! By the way, jenkins can install maven (different versions) and Java for you through Global Tools options in Configurations. What is recommanded approach, letting Jenkins installing maven and java through GUI or configuring this in docker container through Dockerfile?Pane
@IsmarSlomic - This is actually a matter of your own preference. My key criteria to choose between the two is based on centralizing all the configuration in one place. Since Docker is good for configuring both simple and complex environments and can hold the whole configuration in one place, I would stick with it.Hill
F
3

I suggest you take trying to use dynamic|ephemeral docker nodes, instead of manually creating nodes and connecting to them via ssh. Take a look at https://engineering.riotgames.com/news/putting-jenkins-docker-container, it's very powerful and I think it's one of killer usecases for Docker.

Forefoot answered 10/10, 2016 at 15:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.