install Jenkins on Docker
Tags: jenkins, docker, cicd, devops
Published: 2023-12-14 03:26:57

### Introduction
In today's world of DevOps, there are different tools used in achieving the CI/CD pipeline. I tried to install, configure Jenkins on Docker and build my first Job using Jenkins.

### What is Jenkins
Jenkins is an essential tool for setting up Continuous Integration(CI). It helps in building the development, testing, and deployment workflow and also creates a job pipeline.

### Setting up the Environment with Docker
I proceeded with installing Docker Engine. For details on how to install docker visit the official installation page at [docs.docker.com](https://docs.docker.com/engine/install/)
After installing docker, validate the docker environment by running

**`docker ps`**

If the above command goes through without errors, you are all set.

I installed Jenkins with minimal effort using
**`docker run -idt --name jenkins -v jenkins_home:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock -p 8080:8080 -p 50000:50000 jenkins/jenkins:2.346.3-slim`**
If you install it using the instructions above, find out the IP address and go to http://YOUR_IP_ADDRESS:8080 to access Jenkins UI.

After that, you have to select install To start/stop Jenkins with docker, use the following commands,

**`docker start jenkins docker stop jenkins`**

After the installation, you will be asked for the password.

**`/var/jenkins_home/secrets/initialAdminPassword`**

Password can be also fetched from the logs.

**`docker logs jenkins`**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vzo51e2iamc80hvxlgbl.png)
Click on **Select Plugins to Install** when given an option.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g6w4p7aqs4ahzw2xlb2f.png)
This will let you choose the plugins to install on the next page.

Click on **None** to deselect all plugins

Create Admin user

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wn3mwsi7fg6299b1r2od.png)
successfully installed Jenkins and I can proceed with building my first job.

When you Login to Jenkins for the first time, the following is the screen you would see

**NOTE:** If you don't see the page you can restart Jenkins using
**`http://YOUR_IP_ADDRESS:8080/restart`**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ql26ufr5udamzag50wgv.png)

**Creating First Job**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p6dyxpkuf09ilmkq74an.png)

- From Jenkins Main page, click on **New Item**
- Provide a name to the project in Item Name i.e "firstJob". Check against Free Style Project.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9xl08aemj4x72n67gqkb.png)

- Add job description. "My first Jenkins Job".
- Skip Source Code Management and Build Triggers, and scroll down to **Build configurations**.
- From "Add Build Step" select **Execute Shell** and provide commands to execute.
**`#!/bin/bash echo "Hello World, this is my First Job !" sleep 10`**
- Review and click on save to go to the project page.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6p704qktsl2bbnv3tng4.png)
**Building Job for the First Time**

- Click on **Build Now** to launch a build. 
- Once the build is started, you would see the status in the  **Build History** section. 
- Once the build is finished, click on the build number which starts with #. Clicking on the build number e.g #1 will take you to the page which shows the build stats.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tatzhdnqx56b3atcwqvh.png)

I successfully built my first project using Jenkins.