Setting Up Jenkins: Step-by-Step Guide for Beginners

Shubham SharmaShubham Sharma
3 min read

Introduction

Jenkins is a powerful open-source tool that automates the software development process, specially tasks like building, testing and deploying applications. It is premier face of Continuous Integration (CI) and Continuous Delivery (CD) in Agile development.

Depending of the infrastructure, Jenkins can be installed by various techniques. In this article, we will be discussing the process to install Jenkins on an AWS instance based on Ubuntu. The process is same for all other Ubuntu systems and similar for other linux based operating systems.

Prerequisites

  • An Ubuntu instance (local or remote).

  • Docker installed on the system.

  • Basic knowledge of Docker and Jenkins.

If docker is not already installed, follow the following steps:

  • ssh into your instance (if using remote).

  •     # Download script to download and install docker
        sudo apt update
        curl -fsSL https://get.docker.com -o get-docker.sh
    
        # Execute the downloaded script
        sudo sh get-docker.sh
    
        # Verify docker installation
        docker --version
    

    If docker version is seen, it implies docker is installed sucessfully.

Setting up Jenkins

  •     docker pull jenkins/jenkins:lts
    

    If not allowed, use sudo, or allow the current user to use docker commands.

  •     docker run -p 8080:8080 -p 50000:50000 -d \
        > -v jenkins_home:/var/jenkins_home \
        > -v /var/run/docker.sock:/var/run/docker.sock \
        > -v $(which docker):/usr/bin/docker \
        > jenkins/jenkins:lts
    

    -p 8080:8080 : maps port 8080 on local machine to port 8080 of container as port 8080 is default port for Jenkins’ web interface.
    -p 50000:50000 : maps port 50000 on the host to port 50000 inside the container for communication between the Jenkins master and its agent nodes.
    -d : runs the container is detached mode (runs in background).
    -v jenkins_home:/var/jenkins_home : mounts docker’s named-volume ‘jenkins_home’ to ‘/var/jenkins_home’ in container so that jenkins’ data persists even if container is restarted.
    -v /var/run/docker.sock:/var/run/docker.sock : mounts docker socket from host to container to allow Jenkins to interact with the host Docker daemon, enabling it to start and manage docker containers.
    -v $(which docker):/usr/bin/docker : mounts docker binary from host to /usr/bin of container so that docker command is available in Jenkins container.
    jenkins/jenkins:lts : docker image that is to be used to create container.

  • Open port 8080 of the system to interact with Jenkins UI.

  •     #If server’s firewall is active, it may block port 8080 even if it is allowed by AWS.
        sudo ufw status
        sudo ufw allow 8080
        sudo ufw reload
    
  • Visit http://<host-ip>:8080 to interact with Jenkins Interface.

  • To unlock jenkins, you will need to get initialAdminPassword from Jenkins container.

  •     docker ps
    
        #Use the obtained container-id from above command
        docker exec -it <container-id> /bin/bash 
        cd /var/jenkins_home/secrets
        cat initialAdminPassword
        #copy the obtained password
    
  • Follow instructions for initial setup.

Conclusion

Setting up Jenkins on Ubuntu with Docker is a simple and efficient way to start automating tasks and using CI/CD. Docker creates a separate environment for Jenkins, making it easy to manage and run on different systems.

This guide explained how to install Jenkins on Ubuntu using Docker. With Jenkins up and running, you can now automate building, testing, and deploying your software.

0
Subscribe to my newsletter

Read articles from Shubham Sharma directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shubham Sharma
Shubham Sharma

DevOps Engineer | Software Developer | Technology Enthusiast I am a DevOps Engineer with a strong foundation in software development and a passion for building efficient, scalable, and automated solutions. With experience in tools like Jenkins, Docker, Kubernetes, and cloud platforms like AWS, I specialize in streamlining CI/CD pipelines, optimizing infrastructure, and ensuring robust application delivery. Currently, I’m honing my skills in development, DevOps practices, and data structures & algorithms to stay at the forefront of technology. Outside work, I enjoy exploring new ideas, writing blogs about DevOps and development, and continuously learning to enhance my expertise.