What is Jenkins and how to install it on your server

21.08.2020 95 0

One of the great challenges in any software project is the number of repetitive tasks you have to complete. It would be nice if you could automate at least some of those tasks, right? Well, you may just be able to do so thanks to Jenkins.

What is Jenkins you ask? It’s a free and open-source automation server. It allows you to build, test and deploy software while automating some of the tasks in that process. The platform also supports a plethora of plugins which allows you to add a lot of tools to integration and more.

Jenkins allows you to have continuous integration and continuous delivery. All of this may sound complex, but Jenkins allows for easy configuration via a web-interface. It can even help you with –on-the-fly error checks and more. Jenkins is a community-driven project, so it evolves constantly and there are a lot of localized versions and options.

So, how to install Jenkins?

Jenkins is self-contained and Java-based. You can install it on Windows, macOS, several Unix platforms. The most popular and easiest way to install Jenkins is on a single machine.

Before you start

You have to make sure the server covers a few requirements. The server should have 256MB of RAM at the bare minimum. It should have 1GB free drive space (10GB for running it as a Docker container).

It’s highly recommended that you use a server with 1GB RAM or more and 50GB or more free space. This way you can use everything Jenkins can offer.

There are a few software requirements, too:

Have Java installed and a web browser of your choice. For a Windows installation, it should be a 64-bit version and it’s better if it’s as recent as possible.

Docker

Installing Jenkins on Docker is simple. Just get the jenkinsci/blueocean image from the site. It comes with Blue Ocean plugins. Each image comes along with each new release of Blue Ocean.

macOS and Linux

The process is the same. Open the terminal and make a bridge network with this command:

docker network create jenkins

docker network create jenkins

Then run these:

docker volume create jenkins-docker-certs
docker volume create jenkins-data

With them you will share the Docker client TLS certificates.

Next, download and run the docker:dind then use this command:

docker container run \
  --name jenkins-docker \
  --rm \
  --detach \
  --privileged \
  --network jenkins \
  --network-alias docker \
  --env DOCKER_TLS_CERTDIR=/certs \
  --volume jenkins-docker-certs:/certs/client \
  --volume jenkins-data:/var/jenkins_home \
  --publish 2376:2376 \
  docker:dind

Lots of these are optional and you can get more information about them in the official installation docs.

Next, Download the jenkinsci/blueocean image and run it as a container in Docker using the following docker container run command:

docker container run \
  --name jenkins-blueocean \
  --rm \
  --detach \
  --network jenkins \
  --env DOCKER_HOST=tcp://docker:2376 \
  --env DOCKER_CERT_PATH=/certs/client \
  --env DOCKER_TLS_VERIFY=1 \
  --publish 8080:8080 \
  --publish 50000:50000 \
  --volume jenkins-data:/var/jenkins_home \
  --volume jenkins-docker-certs:/certs/client:ro \
  jenkinsci/blueocean

Again, a lot of this is optional.

Installing on Windows

Jenkins doesn’t come with a separate Windows image. But if you install Docker for Windows, and configure it to run Linux containers, you can then install Jenkins, too. The first steps are the same and you have to run these commands one after the other:

docker network create jenkins
docker volume create jenkins-docker-certs
docker volume create jenkins-data

Then you have to run these two:

docker container run --name jenkins-docker --rm --detach ^
  --privileged --network jenkins --network-alias docker ^
  --env DOCKER_TLS_CERTDIR=/certs ^
  --volume jenkins-docker-certs:/certs/client ^
  --volume jenkins-data:/var/jenkins_home ^
  docker:dind

Then:

docker container run --name jenkins-blueocean --rm --detach ^
  --network jenkins --env DOCKER_HOST=tcp://docker:2376 ^
  --env DOCKER_CERT_PATH=/certs/client --env DOCKER_TLS_VERIFY=1 ^
  --volume jenkins-data:/var/jenkins_home ^
  --volume jenkins-docker-certs:/certs/client:ro ^
  --publish 8080:8080 --publish 50000:50000 jenkinsci/blueocean

And you are done with the installation.

Leave a Reply

Your email address will not be published.