Monday, March 17, 2025

JENKINS (1)

 


I was thinking a lot, what shoudl be next post. I already started draft of usage of Docker advanced topics (I will post it in the future). I wanted to create real life example. I came up with idea, to connect Docker usage and Jenkins learning. I realize despite Jenkins simiplicity, in right hands, it is very powerfull tool.

I have plan to divide Jenkins post in few step real life usage.


Plan:

Chapter 1. Install Jenkins (with Docker)

Chapter 2. Create Freestyle Jobs

Chapter 3. CI/CD project


Chapter 1. Install Jenkins


Before we begin, I need set reservation, Docker need to installed.

Before installation, I woudll like to confirm, that Jenkins is not installed.

Command docker image ls  -all and docker ps, show status before installation.



One of core feature in Docker is networks. It is 5 type of Docker network. For Jenkins we will user network type: bridge.(1

Containers in the network can communicate with each other using their own IP addresses and DNS names, but they’re isolated from those outside the network(2)(3).

    docker network create jenkins



Dockerfile

FROM jenkins/jenkins:2.492.2-jdk17

USER root

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

    install -m 0755 -d /etc/apt/keyrings && \

    curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc && \

    chmod a+r /etc/apt/keyrings/docker.asc && \

    echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] \

    https://download.docker.com/linux/debian $(. /etc/os-release && echo \"$VERSION_CODENAME\") stable" \

    | tee /etc/apt/sources.list.d/docker.list > /dev/null && \

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

    apt-get clean && rm -rf /var/lib/apt/lists/*

USER jenkins

RUN jenkins-plugin-cli --plugins "blueocean docker-workflow"

    

Dockerfile build command:

docker build -t myjenkins-blueocean:2.492.2-1 .


Initial run localhost:8080, show information how unlock Jenkis.


To unlock Jenkins, initial password is needed. To get password, I enter inside Docker container. There are CLI commands, but I wanted to do this way.

I have to know container ID. To get container ID , I run command: docker ps



When I have container ID, I run command below, to get into container with bash shell.

docker exec -it 988c18960248 /bin/bash


I run pwd, to confim my location in Docker container. 
Then I go to location /var/jenkins_gome/secrets/ and cat file initialAdminPassword
I have small typos, but finally I get initial Admin password.


When I have password, I paste it to unclock Jenkins.







Password was correct, so I continued to configure Jenkins. There was information to install suggested plugins. I click it.


Jenkins installation was completed.







Docs:

1. https://www.jenkins.io/doc/book/installing/docker/

2. https://spacelift.io/blog/docker-networking

3. https://docs.docker.com/engine/network/drivers/bridge/


PS. Jenkins can be made in Docker compose:

https://dev.to/msrabon/step-by-step-guide-to-setting-up-jenkins-on-docker-with-docker-agent-based-builds-43j5






No comments:

Post a Comment

K8s cluster - bash install

     In my homelab, I testes another method of installation of Kubernetes. Average time of installation of Kubernetes via Ansible was 15 min...