Skip to content

Deploy a Jenkins server with Docker containers and create a CI/CD pipeline

Notifications You must be signed in to change notification settings

Tony-Dja/Jenkins_CI-CD_pipeline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docker Build Docker Build example workflow

Jenkins Docker Docker

Deploy a Jenkins server with Docker containers
+ Create a CI/CD pipeline

project

Dockerfile

To deploy the Jenkins server, we build an image from => Jenkins2.375
Just install inside, the Docker CLI, Docker compose and BlueOcean plugin from Jenkins to show graphical interface for pipelines.

We build the Dockerfile directly from Docker-compose.yml, but you can also build with GitHub actions, Push image on DockerHub and Pull it from the Docker compose file.
You could find this workflow with GitHub Actions in the ".github" folder.

FROM jenkins/jenkins:2.375-jdk11

USER root

RUN apt-get update && apt-get install -y apt-transport-https \
       ca-certificates curl gnupg2 \
       software-properties-common

RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -

RUN apt-key fingerprint 0EBFCD88

RUN add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"

RUN apt-get update && apt-get install -y docker-ce-cli

RUN curl -L "https://github.com/docker/compose/releases/download/`curl -fsSLI -o /dev/null -w %{url_effective} https://github.com/docker/compose/releases/latest | sed 's#.*tag/##g' && echo`/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && \ 
    chmod +x /usr/local/bin/docker-compose && \ 
    ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

USER jenkins

RUN jenkins-plugin-cli --plugins blueocean

Deploy containers

To run containers just execute the following command :

docker compose up -d

The jenkins service is exposed on port 8080

services:
  jenkins:
    container_name: jenkins-server
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - 8080:8080
      - 50000:50000
    environment:
      - DOCKER_HOST=tcp://docker:2376
      - DOCKER_CERT_PATH=/certs/client
      - DOCKER_TLS_VERIFY=1
    networks:
      - local_jenkins
    hostname: jenkins
    restart: always
    volumes:
      - jenkins-data:/var/jenkins_home
      - jenkins-docker-certs:/certs/client:ro
    depends_on:
      - docker

Check the containers running :

docker ps

screen

Now to display the Jenkins server on your browser :

http://localhost:8080

screen

For the first start you have to retrieve the initial password generate by Jenkins.
To do that you must connecting on the jenkins-server container and display the password file. Then enter the password and validate.

docker exec -it jenkins-server /bin/bash

inside the container :

cat /var/jenkins_home/secrets/initialAdminPassword 

screen

It' OK, so now create a user and confirm the IP address with the open port.

screen

screen

Create Jenkins project

We are going to create a Jenkins pipeline to Build a simple HTML5 website. You can use my repository or take yours.

https://github.com/Tony-Dja/Docker-contenerized-website

Enter a name for your project

screen

Click on checkbox "Build with parameters", and add 2 variables with string type :

  - IMAGE_NAME => name of Docker image you are going to build
  - IMAGE_TAG => Tag of the image

screen

screen

From the Build Steps section, select "execute shell script"

screen

And last, add script to clone the repo, and Build image. Then validate project

screen

Run pipeline

To run pipeline, click on "Build with parameters" and "Build"

screen

The job is running, you can watch job in progress

screen

The job is finished

screen

Blue Ocean plugin

In the Dockerfile, we install Blue Ocean plugin. It allows to visualize a graphic interface for our pipeline.
You can find the link in Jenkins navigation menu

screen

screen

About

Deploy a Jenkins server with Docker containers and create a CI/CD pipeline

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published