Jenkins

1. Jenkins Infrastructure

Jenkins is a self-contained Java-based program, ready to run out-of-the-box, with packages for Windows, Mac OS X and other Unix-like operating systems.

  • Master Server
    • Controls pipelines
    • Schedules builds
  • Agent/Minions
    • Performs the build

Agent Types

  • Pernament Agents
    • Always connected to the master
    • Can be used to run multiple builds
  • Cloud Agents
    • Dynamically created and destroyed
    • Can be used to run multiple builds

Build types

  • Freestyle
    • Simple build
    • No dependencies
    • No pipeline
  • Pipeline
    • Complex build
    • Dependencies
    • Pipeline

Build Jenkins with Docker

FROM jenkins/jenkins:2.346.2-jdk11

USER root

RUN apt-get update && apt-get install -y \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

RUN curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

RUN echo \
    "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
    $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null

RUN apt-get update && apt-get install -y \
    docker-ce \
    docker-ce-cli \
    containerd.io

RUN usermod -aG docker jenkins

USER jenkins

RUN jenkins-plugin-cli --plugins "blueocean:1.25.3 docker-workflow:1.28"


Build Jenkins Image

docker build -t jenkins-blueocean:1.1 .

Docker network

docker network create jenkins


# list networks
docker network ls

Run Jenkins

docker run \
  --name jenkins-blueocean \
  --restart=on-failure --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 jenkins-blueocean:1.1


jenkins admin password

docker exec jenkins-blueocean cat /var/jenkins_home/secrets/initialAdminPassword

Go inside the container

docker exec -it jenkins-blueocean bash

Docker image delete

docker image rm jenkins-blueocean:1.1

alpine/socat container to forward traffic from Jenkins to Docker Desktop on Host Machine

docker run -d --restart=always -p 127.0.0.1:2376:2375 --network jenkins -v /var/run/docker.sock:/var/run/docker.sock alpine/socat tcp-listen:2375,fork,reuseaddr unix-connect:/var/run/docker.sock


Get ip address of the container

docker inspect a08cdd81f795af0b09eacf9d539ffc173f2c26ad711a22ad56a80a9d2bd32361 | grep IPAddress
    

Configure Clouds

Jenkins


© 2019. All rights reserved.

Powered by NightHawk