How to Set Up Jenkins for Automation: A Complete Beginner’s Guide to CI/CD

1.22K 0 0 0 0

📘 Chapter 2: Installing and Configuring Jenkins

🔐 Introduction

Now that you understand what Jenkins is and why it’s vital in modern CI/CD workflows, it’s time to install and configure Jenkins to begin your automation journey. Whether you're setting it up on a local machine for testing or on a production server for real-world projects, this chapter provides a step-by-step guide to getting Jenkins up and running — securely and efficiently.


💡 What You’ll Learn in This Chapter

  • Jenkins installation methods (WAR, Docker, packages)
  • Post-installation setup and admin configuration
  • Recommended plugins and UI tips
  • Credential setup and security best practices
  • Troubleshooting installation issues

🛠️ Prerequisites

Requirement

Details

Java (JDK 11 or higher)

Required to run Jenkins

Minimum RAM

2 GB (recommended 4 GB)

Disk Space

Minimum 1 GB (for Jenkins and build artifacts)

Internet Access

For downloading plugins and dependencies

Browser

Latest version of Chrome, Firefox, or Edge


️ 1. Installing Jenkins


Method 1: Jenkins WAR File (Portable & Quick)

  1. Download Jenkins WAR from: https://www.jenkins.io/download
  2. Open terminal or command prompt
  3. Run the WAR file:

bash

 

java -jar jenkins.war

  1. Visit http://localhost:8080 to access the Jenkins UI

Best for: Quick testing, local development


Method 2: Install Jenkins on Ubuntu/Debian

bash

 

# Add Jenkins repo

wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -

sudo sh -c 'echo deb https://pkg.jenkins.io/debian binary/ > /etc/apt/sources.list.d/jenkins.list'

 

# Update & install

sudo apt update

sudo apt install jenkins

Then start Jenkins:

bash

 

sudo systemctl start jenkins

sudo systemctl enable jenkins

Visit Jenkins at: http://<your-server-ip>:8080


Method 3: Install Jenkins Using Docker

bash

 

docker run -d -p 8080:8080 -p 50000:50000 --name jenkins \

  -v jenkins_home:/var/jenkins_home \

  jenkins/jenkins:lts

Use docker exec -it jenkins cat /var/jenkins_home/secrets/initialAdminPassword to get the admin password.

Best for: Isolated setup, easy teardown, cross-platform use


Method 4: Cloud Setup (Optional)

You can deploy Jenkins on cloud services like:

  • AWS EC2
  • Azure VM
  • Google Compute Engine
  • Or even Kubernetes using Helm charts

Cloud setups allow remote access, scalability, and integration with cloud DevOps pipelines.


🔑 2. Jenkins First-Time Setup

Once installed:

  1. Visit http://localhost:8080
  2. Unlock Jenkins using the admin password (found in terminal logs or /var/jenkins_home/secrets/initialAdminPassword)
  3. Select “Install suggested plugins”
  4. Create an admin user
  5. Configure the Jenkins URL
  6. Jenkins is now ready!

🔌 Recommended Plugins to Install

Plugin Name

Purpose

Git Plugin

Pull code from GitHub, GitLab, Bitbucket

Pipeline Plugin

Enable scripted/declarative CI/CD workflows

Docker Pipeline

Run CI/CD tasks in Docker containers

Blue Ocean

Modern pipeline UI with visual stages

Email Extension

Send alerts for build success/failure

Credentials Binding

Manage secrets securely in builds


🔧 3. Configuring Jenkins System Settings

Navigate to:
Manage Jenkins → Configure System

️ Key Configurations:

  • Set Jenkins URL for correct webhook redirection
  • Define Global Tool Configurations (Java, Git, Maven, etc.)
  • Configure email server for notifications
  • Set up proxy if required behind a firewall
  • Customize workspace directory (optional)

🛡️ 4. Securing Jenkins

Security is critical in any automation setup. Jenkins offers several options to protect credentials and jobs.

Security Feature

How to Enable

User authentication

Use Jenkins’ own database or integrate with GitHub OAuth

Role-based access control

Use Role Strategy Plugin for fine-grained permissions

Disable CLI remoting

Reduce remote attack surface

Secret masking

Hide passwords/API keys in logs

HTTPS configuration

Use reverse proxy with SSL termination (e.g., NGINX)


🔐 Credentials Management

Store sensitive information like:

  • GitHub tokens
  • SSH keys
  • AWS credentials
  • Docker Hub login

Manage from:
Manage Jenkins → Credentials

Use Credential IDs in pipelines to inject them securely.


🧪 5. Verifying Jenkins Installation

Once installed and configured:

  • Create a simple freestyle job
  • Add a build step: "Execute shell" or "Execute Windows batch command"
  • Add: echo Hello, Jenkins!
  • Run the job and check console output

You should see:

pgsql

 

Started by user admin

Building on master

Hello, Jenkins!

Finished: SUCCESS

Congratulations, your Jenkins setup works!


🧘 6. Troubleshooting Common Issues

Issue

Solution

Port 8080 already in use

Change Jenkins port in jenkins.xml or Docker run command

Cannot access Jenkins UI

Check firewall, proxy, or server IP address

Plugin installation stuck

Restart Jenkins or use “Advanced” tab to upload manually

Build workspace not cleaned

Enable workspace cleanup post-build

Credentials not available in pipeline

Ensure correct scope and ID used


🧠 Tips for Beginners

  • Use the Blue Ocean plugin for easier pipeline management
  • Back up /var/jenkins_home regularly
  • Read Jenkins logs: Manage Jenkins → System Log
  • Avoid overloading master node — configure agents for scalability
  • Learn Jenkinsfiles for powerful, reusable CI/CD scripts

📘 Summary

Installing and configuring Jenkins might seem like a lot at first, but it’s surprisingly manageable when broken down into simple steps. Whether you're experimenting locally, using Docker for containers, or setting up in the cloud — Jenkins gives you a solid foundation for automation.

With the right plugins, security configurations, and a few test jobs, you’ll be ready to start automating your entire software pipeline.


Jenkins isn’t just an automation server — it’s your DevOps launchpad.

Back

FAQs


1. What is Jenkins and why is it used in automation?

Jenkins is an open-source automation server that helps developers automate building, testing, and deploying code. It enables Continuous Integration and Continuous Delivery (CI/CD), making software delivery faster and more reliable.

2. What are the system requirements to install Jenkins?

To install Jenkins, you need:

  • Java 11 or later (Java 17 recommended)
  • At least 2 GB of RAM and 1 GB of disk space
  • A modern browser for accessing the Jenkins UI

3. What’s the easiest way to install Jenkins for beginners?

The simplest way is to use the Jenkins WAR file:

java -jar jenkins.war

Alternatively, you can use a Docker container for a quick and clean setup:

docker run -p 8080:8080 jenkins/jenkins:lts

4. How do I connect Jenkins to my GitHub repository?

Install the Git and GitHub plugins, then:

  • Create a new job or pipeline
  • Choose “Git” as the source code management
  • Enter the GitHub repo URL and credentials if needed
  • Add a webhook to trigger Jenkins builds on each push

5. What is a Jenkins Pipeline?

A pipeline is a script-based workflow written in Groovy DSL that defines your automation steps (e.g., build, test, deploy). Pipelines can be declarative (simplified) or scripted (flexible).

6. What plugins should I install first in Jenkins?

For basic automation, start with:

  • Git plugin (source control)
  • Pipeline plugin (workflow scripting)
  • Docker plugin (if using containers)
  • Blue Ocean (modern UI for pipelines)
  • Email Extension (build notifications)

7. Can Jenkins be used with Docker and Kubernetes?

Yes! Jenkins integrates with Docker for building images and with Kubernetes for scaling jobs using agents. Tools like Jenkins X also help automate deployments in Kubernetes.

8. How do I secure my Jenkins installation?

  • Use HTTPS for the web UI
  • Create individual user accounts
  • Configure role-based access controls
  • Mask secrets and tokens in logs
  • Regularly update plugins and Jenkins core

9. How do I trigger Jenkins builds automatically?

You can:

  • Use webhooks from GitHub/GitLab
  • Schedule jobs using CRON syntax
  • Trigger builds after another job completes
  • Use a poll SCM trigger to check for changes periodically

10. Is Jenkins free to use for commercial projects?

Yes! Jenkins is 100% free and open-source, licensed under MIT. You can use it in personal, educational, and commercial environments without restriction.