Jenkins is an automation platform which allows us to build , test and deploy software using pipelines.
- Master Server:It is responsible to controls pipelines and schedules builds.
- Agents/Minions:An agent is a service that runs the jobs/builds defined in our pipeline.
- There are two type of agents:
- Permanent agents: They are dedicated servers for running jobs.
- Cloud agents:
- In Jenkins, a cloud agent is a Jenkins agent that is launched dynamically in a cloud environment.
- Cloud agents are useful when you need to scale your build capacity up or down based on demand .
It consists of:
- Freestyle builds:are the simplest method to create a build.A freestyle project in Jenkins is a type of build job that allows users to automate simple tasks such as running tests, creating and packaging applications, producing reports, or executing commands .
- Pipelines:are the set of automated tasks which helps in to develop and deploy software faster.
docker build -t myjenkins-blueocean:2.414.2 .
#IF you are having problems building the image yourself, you can pull from my registry (It is version 2.332.3-1 though,
the original from the video)
docker pull jenkins/jenkins
docker network create 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/jenkins
Note:Now run run 'docker ps' you will see our jenkins container is running there on port localhost:8080
docker exec 'jenkin container name ' cat /var/jenkins_home/secrets/initialAdminPassword
https://localhost:8080/
- docker exec -it 'container name' bash :used to run Jenkins workspace in bash mode.
- cd /var/jenkins_home : used to move to the jenkin home page.
- cd ~ : go back to the home directory
- docker exec -u 0 'container name' apt update
- docker exec -u 0 'container name' apt install python3-pip -y
- Install any cloud plugin example docker plugin .
- Go to manage jenkins-> System Configuration -> Add cloud -> Choose cloud plugin (i.e docker in our case).
- If you are running jenkins as container, in the docker host uri field you have to enter unix or tcp address of the docker host. But since you are running jenkins as container, the container can't reach docker host unix port.
- So, we have to run another container that can mediate between docker host and jenkins container. It will public docker host's unix port as its tcp port. Follow the instructions to create socat container https://hub.docker.com/r/alpine/socat/
-
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.so alpine/socat tcp-listen:2375,fork,reuseaddr unix-connect:/var/run/docker.sock
- docker inspect 'container_id' | grep IPAddress
- After creating the socat container, you can go back the docker configuration in jenkins and enter tcp://socat-container-ip:2375
- Note: Make sure that you have enabled CSRF Protection from global configuration.
- Test Connection should succeed now.
- There 2 ways to run pipeline in Jenkins:
- By writing pipeline script in pipeline configuration.
- By creating seperate 'Jekinfile' and then adding that file in pipeline configuration using git.