DEV Community

Cover image for Mastering Jenkins: A Step-by-Step Guide to Setting Up and Supercharging Your CI/CD Workflow
Hashim HB
Hashim HB

Posted on

Mastering Jenkins: A Step-by-Step Guide to Setting Up and Supercharging Your CI/CD Workflow

What is Jenkins?

→ Jenkins is an open-source tool used to automate tasks in software development, mainly focusing on Continuous Integration (CI) and Continuous Delivery (CD).

→ It also helps developers automatically build, test, and deploy their code changes whenever they make updates.

Features of Jenkins:

  • CI/CD INTEGRATIONS

  • PIPELINES

  • EASY INSTALLATION

  • EASY CONFIGURATION

  • DISTRIBUTED

  • EXTENSIBLE

  • OPEN-SOURCE

How to Set Up Jenkins in your Local Machine?

☆ There are many ways in which can set up you can choose which suits you the best

Image description

✦ You can set up in Windows also but I am going to teach you how we can setup Jenkins locally with Oracle VirtualBox VM.

✦ First create a VM (Virtual Machine) using a Virtual Box and install the Linux (Ubuntu/CentOS) as your wish

Image description

✦ Open Terminal in any one of the following Linux Distros it might be different for UBUNTU you can check Jenkins documentation for that I will guide you for CentOS.

sudo wget -O /etc/yum.repos.d/jenkins.repo \ https://pkg.jenkins.io/redhat-stable/jenkins.repo
Enter fullscreen mode Exit fullscreen mode
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
sudo yum upgrade
Enter fullscreen mode Exit fullscreen mode
# Add required dependencies for the jenkins package
sudo yum install fontconfig java-17-openjdk
sudo yum install jenkins
sudo systemctl daemon-reload
Enter fullscreen mode Exit fullscreen mode

✦ Start Jenkins by using systemctl

sudo systemctl enable jenkins
sudo systemctl start jenkins # to start jenkins
sudo systemctl status jenkins # to check the status if its running or not 
Enter fullscreen mode Exit fullscreen mode

✦ If everything went well, the beginning of the status output shows that the service is active and configured to start at boot(enabled)

Image description

✦ Now that Jenkins is up and running, let’s adjust our firewall rules so that we can reach it from a web browser to complete the initial setup.

IMPORTANT STEP :

✦ check if firewall is installed in the system

sudo yum install firewalld
sudo systemctl enable firewalld
sudo reboot
Enter fullscreen mode Exit fullscreen mode

✦ Now everything is done now we can start using Jenkins

ifconfig
Enter fullscreen mode Exit fullscreen mode

✦ By running this command we get the IP-Address of Linux system use this IP-Address to access the Jenkins dashboard in the web-browser by typing ipaddress:8080 and enter

✦ This will successfully Land you to this page:

Image description

✦ Use the terminal in your VM and run

sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Enter fullscreen mode Exit fullscreen mode

✦ Copy the 32-character alphanumeric password from the terminal and paste it into the Administrator password field on the Jenkins page. Then, click Continue.

Image description

✦ Click on Install suggested plugins

Image description

✦ It will Install the required plugins

Image description
✦ Once all the plugins are installed then:

Image description
✦ Fill in the required fields and proceed

Image description
✦ URL will be provided i have removed for security purposes just click on save and finish

Image description
✦ Now you have successfully done the setup for Jenkins

Image description
✦ This is what the Jenkins Dashboard Looks like

Now this is for the Linux system it will only run in Linux environment if we want to access in our local machine (Windows) you need to follow certain steps:

In Linux environment run the following commands:

sudo firewall-cmd --permanent --zone=public --add-port=8080/tcp
sudo firewall-cmd --reload
Enter fullscreen mode Exit fullscreen mode

✦ Both the commands should give SUCCESS or else you have done something wrong

Setting Up Port Forwarding

  1. Open VirtualBox VM settings.

  2. Navigate to the NAT network adapter settings.

  3. Click Advanced and then Port Forwarding.

  4. Add a new rule named "Jenkins".

  5. Set Protocol to TCP.

  6. Enter Host IP as 127.0.0.1 and Host Port as 8080.

  7. Guest Port should also be set to 8080.

  8. Click OK to save the settings.

Image description

After this step→ Open your browser and go to 127.0.0.1:8080 to access Jenkins, you will land on the getting started Jenkins page:

Image description

✦ Enter the Username and Password which you created Before and there you go

✦ You have Successfully setup Jenkins in your Local Machine

How to create Jenkins first Job?

✦ Click on → Create a Job

Image description

✦ Then give a name for the job and select freestyle Project as we are just starting off.

Image description
✦ You will get a page something like this:

Image description
✦Scroll down to Build Steps:

Image description
✦Choose the option what you like

✦We will choose Execute Shell and write the command that you want to execute and save

Image description

Image description

✦ Now just click on Build Now and that it you have successfully created your first job in Jenkins

✦ After the job is created click on the job and get to see the following:

Image description

Image description

✦ This was the output and we successfully created and saw the output of the command in Jenkins

✦ We can even see the number of jobs that we have created

Image description
This was all about Jenkins Hope You guys like it.

Top comments (0)