Our Blog

Building Your First CI/CD Pipeline (Even If You're a Beginner)

Building Your First CI/CD Pipeline (Even If You're a Beginner)

Jenkins is a cornerstone in the world of CI/CD (Continuous Integration/Continuous Delivery), playing a vital role in automating key parts of the software development process. By streamlining tasks like code integration, testing, and deployment, Jenkins enables developers to focus on building features and improving user experiences without getting bogged down by repetitive workflows. This blog will guide you through the basics of Jenkins, from installation to creating your first pipeline, providing a hands-on introduction to how Jenkins can transform your development pipeline. As you become more familiar with its capabilities, you'll discover how advanced features like Jenkinsfiles and tool integration can create a seamless, automated workflow from development to production. Mastering Jenkins isn’t just about learning a new tool—it’s about enhancing your efficiency and understanding of the entire software development lifecycle.


Section 1: What is CI/CD? What is Jenkins?

In software development, understanding Continuous Integration and Continuous Deployment (CI/CD) is crucial. CI/CD is a methodology that automates the building, testing, and deployment of software changes to production. Its primary goal is to reduce the time between making changes to the code and deploying those changes in a live environment.

At the core of this process is Jenkins, an open-source automation server widely recognized in the development community as one of the top CI/CD tools. Jenkins is not just limited to building and deploying projects—it also automates other critical tasks such as securing code, conducting code reviews, and tracking application performance after deployment.

What sets Jenkins apart is its vast library of plugins. These plugins provide specialized functionality and offer flexibility to accommodate various project needs. This helps improve efficiency, boost productivity, and streamline project management across all stages of development, making Jenkins a preferred choice for implementing CI/CD pipelines.

Section 2 : Step-by-Step Installation on Ubuntu 22.04

Please these steps for installing Jenkins on Ubuntu 22.04
Update the Ubuntu 22.04
First, update your package list to make sure you have the latest version of installed packages.

sudo apt update

sudo apt update

sudo apt upgrade -y

sudo apt upgrade -y

Install the Java JDK
Jenkins requires Java to run. Install the OpenJDK package:
sudo apt install openjdk-11-jdk -y

sudo apt install openjdk-11-jdk -y

Verify the installation:
java -version

java -version

Add Jenkins Repository
Jenkins is not available in Ubuntu’s default repository. To install it, add the Jenkins repository and GPG key.

curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null

curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null

Add the Jenkins repository to the system:

echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null


echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \<br/>
              https://pkg.jenkins.io/debian-stable binary/ | sudo tee \<br/>
              /etc/apt/sources.list.d/jenkins.list > /dev/null

Install Jenkins
Now, update the package index and install Jenkins.

sudo apt update

sudo apt update

sudo apt install jenkins -y

sudo apt install jenkins -y

Start and Enable Jenkins Service
After installation, start Jenkins and enable it to start at boot.

sudo systemctl start jenkins
sudo systemctl enable jenkins


sudo apt update

You can check the status of Jenkins to confirm it's running:

sudo systemctl status jenkins

sudo apt update

Access the Jenkins Admin Interface
Before accessing the admin interface, please ensure port # 8080 is currently accepting connections. After modifying the firewall rules, open up your favorite browser and then enter the URL: http://<YOUR-IP-ADDRESS>:8080

Accessing Jenkins Admin interface for the first time

You will need the initial password to access it. It is located in /var/lib/jenkins/secrets/initialAdminPassword. Use the following command to access it:

cat /var/lib/jenkins/secrets/initialAdminPassword

View the temporary password

After you have entered the password, you will be redirected to the following page.

Optional tasks

Proceed to click on Install suggested plugins. You will be redirected to the following page:

Install Suggested Plugins

Once plugins are installed you will be redirected to the page for setting up admin user and password.

Set username and password

Click on 'Save and Continue' and you will be redirected to the following page displaying the ADMIN URL for Jenkins.

View the summary page

Now click on 'Save and Finish' button to continue as shown. You will be redirected to the following page.

View the summary page

Next click on 'Start using Jenkins' button to continue

Click button to continue to Admin Dashboard

Congratulations!!! You have now successfully configured Jenkins on your server.

Section 3 : Building Your First Pipeline using Jenkins

Let's assume we have a simple Python script that prints out "Hello World". We need to ensure that Python and Pipeline Plugins are installed. Let's go to the Jenkins Admin on the browser. On 'Dashboard' page, you will find a link to 'Manage Jenkins' - please click it. It will redirect you to the following page:

Manage Jenkins page on the Admin

Now click on the 'Plugins' link and you will be redirected to the following page

Manage Jenkins page on the Admin

Please select 'Installed Plugins' and the following page will be displayed:

Manage Jenkins page on the Admin

Using the Search box 'Search installed plugins' - search for Python and Pipeline plugins and verify which one are installed. (Note you may get multiple types of plugins for each query).

From the following screenshot, it appears that Pipeline plugin is installed.

Pipeline plugin is installed

However search for the Python plugin returned no results.

Pipeline plugin is installed

In order to install 'Python' plugin, please click on the 'Available plugins' link on the left hand side (as shown in the following screenshot)

Available Plugins page

Now add 'Python' in search area and available plugins for Python will be displayed as shown in the screenshot:

Available Plugins page

Check the 'Checkbox' next to the Python Plugin and then click on the 'Install' button.

Available Plugins page

Once you have clicked on the 'Install' button - it will download and install the plugin. You will see a screen as shown below:

Available Plugins page

Now both prerequisites have completed, we can start with building the pipeline. Go the Jenkins's Dashboard and click on 'New Item'. You will be taken to the following page:

Available Plugins page

On this page add 'jenkins-101' as the item name and click on 'Pipeline' item type. Following screenshot illustrates this point:

Available Plugins page

Click 'Ok' button to continue. You will taken to 'Configure' page for the pipeline.

Most important part is the 'Pipeline' section towards the end of the page. Please review the following screenshot:

Available Plugins page

Creating the Jenkins File Script

We will use a simple Jenkins file that does the following:
- Pull the latest code from 'main' branch of the repostitory
- Check if Python is installed on the Jenkin's server
- Install dependencies if requirements.txt file is present in the report
- Run the python script

Sample Jenkins file

Now let's add this Jenkins file in the pipeline box for 'New Pipeline Configuration screen' as shown below:

Sample Jenkins file

Click on 'Save' button to continue to the next screen. You will be taken to the main page for the Jenkins Pipelin (jenkins-101) as shown below:

Sample Jenkins file

We can run/build the pipeline by clicking on 'Build Now' button on the left hand side. You will see a small window appear on the left hand side under 'Build History':

Sample Jenkins file

You can see more details by click on the #1. Upon clicking you will be taken to the following page

Sample Jenkins file

In this case, you can see that pipeline build failed. In order to find the reason for the failure, we need to check the details of pipeline execution. We can find these details on 'Console Output' page. Click on the Console Output link and you will directed to the following page.

Sample Jenkins file

Now let's fix the Python script and try building the pipeline again. You will see #2 is added when you click on 'Build Now' link. It will show green tick indicating the pipeline has successfully executed.

Sample Jenkins file

To get more details, click on '#2' link and you will be redirect build information page

Sample Jenkins file

Click on the console output to see in-depth information about this pipeline execution.

Sample Jenkins file

Congratulations you have now successfully running a pipeline using Jenkins.

You can find all code files and scripts: Click here.

In this article, we also walked through the installation process of Jenkins, giving you a hands-on approach to setting it up. You've even created a simple Jenkins pipeline, which is at the heart of every CI/CD process. With Jenkins, automating each step of the delivery pipeline becomes much easier—from pulling the latest code from a repository to monitoring deployed code in production.

The more you use Jenkins, the more you'll understand why it's so valued in managing CI/CD workflows. It allows teams to focus on important tasks like building new features, fixing bugs, and improving user experiences, instead of getting bogged down with repetitive manual tasks.

How FAMRO can help your in your DevOps Project?

Ready to streamline your software development process with Jenkins? Our team of experts can help you fully harness the power of CI/CD automation to improve efficiency, reduce errors, and accelerate your delivery pipeline. Whether you’re just starting with Jenkins or looking to optimize your existing setup, we offer tailored solutions to fit your company's unique needs. Let us handle the complexities of installation, configuration, and pipeline automation, so your team can focus on what they do best—building great products. Contact us today to learn how we can help you transform your development workflow with Jenkins!

Please don't hesitate to Contact us for free initial consultation.

Our solutions for your business growth

Our services enable clients to grow their business by providing customized technical solutions that improve infrastructure, streamline software development, and enhance project management.

Our technical consultancy and project management services ensure successful project outcomes by reviewing project requirements, gathering business requirements, designing solutions, and managing project plans with resource augmentation for business analyst and project management roles.

Read More
2
Infrastructure / DevOps
3
Project Management
4
Technical Consulting