Getting Started with Jenkins using Docker and Create a Jenkins Job

Pranav T P
5 min readOct 31, 2023

Installing Jenkins using Docker and being familiar with Jenkins jobs.

Introduction

Jenkins is one of the most popular CI/CD tools or an automation server that allows developers to build, test and deploy software. If you are familiar with CI/CD concepts and DevOps you might have already experienced Jenkins. This is an open-source automation server and you can install Jenkins to your local workstation regardless of the OS you use. Whether you use Windows or Linux or macOS, you can find a relevant way to install Jenkins.

But I personally prefer to have Jenkins installed in a Docker Container because I could start, stop, maintain and remove the Jenkins easily. Also, since it’s running inside a Docker container, it runs in a sort of virtual environment. So, in this tutorial, I explain how you could achieve this task step by step. If you’re a beginner, I suggest you follow along with me. For this tutorial, I’m using a Mac computer, but since we’re running the Jenkins inside Docker, you don’t have to worry even you’re not using macOS.

Install Docker

First of all, you need to have Docker installed on your computer. If. you don’t have it already, use the link below to download and install it.

Run Jenkins as a Docker Container

Once you download and set up docker on your computer, you can get the Jenkins via the Docker run command as follows.

$ docker run -p 8080:8080 -p 50000:50000 -d -v 
jenkins_home:/var/jenkins_home jenkins/jenkins:lts

Here, we need to set a volume for the docker container because we need to keep those details without getting removed each time we stop the container. So the volume helps us to retain the content.

You can find more information regarding the installation process via the link below.

Start the Server

Once we run the above command, our container will start and release the terminal since we use the -d (detach mode) flag in the command. Then you can go to localhost:8080 on your browser to access the server. If you didn’t get the page loaded, go back to your terminal and run the docker ps command to verify whether the container runs in the background.

Once you navigate to localhost:8080 you will be asked for an admin password to unlock Jenkins.

You can get the admin password from this path and also you can find it in the logs. Run the docker logs <container-id> command to open logs and grab the password and paste it here. Then continue and select Install Suggested plugins and let them be installed.

Once it’s done, Jenkins will ask you to create an account; so give a username and the password and create your account. Next time you log in, you will have to enter these credentials.

All good! now your Jenkins server is ready to be used.

Run your first Jenkins Job

When you log in the first time, you will not be having jobs in the dashboard. So, let’s create our first job.

Before Creating a first job, We need to install the Plugins so need to install the Github Integration, Maven Integration, Maven Invokes. Once’s they are installed we are ready to create our first job.

First, Select New Item in the dashboard and give an item name(ex: Jenkins-Example-java). Then select Maven Project which is often used and you can see more options in the list too. After that, click ok.

Since this is our first job, let’s make it simple. Go to Configure tab on the window that opened. Then click Gitand give the Github Project url ( https://github.com/pranavparamesh/Jenkins-Example-Java.git ) and click Apply and then Save.

Now our job is ready and to run the job, click the Build Now on the left pane. A green checkmark will be displayed in the Build History section if your job runs correctly. If you don’t get it working properly, you’d see a red cross mark in the Build History.

Once the job is completed its’ run, click the green checkmark to see the console output with more details. In that window, you’d see Successhas been printed out and also you could the steps are taken out in the job run process.

Congratulations! You have successfully run your first job on Jenkins.👍Additionally, in a single job, you can have multiple Build steps which allows you to run several commands. Also, you can have multiple Post-build Actions in your job. Post-build Actions section can be used to specify your Artifacts and eventually once the job run is completed, you’d get a quick link to access your Artifacts easily.

Thank you for reading! Hope you liked, enjoyed and found the information useful in this article.

--

--

Pranav T P

I'm a Pranav T P. pursuing my Master (Mtech) at PES University, Banglore in a stream of Cloud Computing