CI/CD Workflow with Jenkins: A Beginner’s Guide to Installation, Configuration, and Best Practices

Utsav Desai
6 min readApr 9, 2023

--

What is Continuous Integration(CI)?

Continuous Integration (CI) is a software development practice that involves integrating code changes from multiple developers into a shared code repository frequently and automatically. The primary goal of CI is to catch and resolve issues in the codebase as early as possible in the development cycle.

CI involves using automated tools and processes to build, test, and validate code changes automatically. Developers regularly commit code changes to a shared code repository, which triggers a build process that compiles the code and runs automated tests to check for errors, bugs, and other issues. If any issues are detected, the CI system immediately notifies the development team so they can fix the problem quickly.

What is Continuous Delivery (CD)?

Continuous Delivery (CD) is a software development practice that involves automating the entire software delivery process from code changes to production deployment. The primary goal of CD is to ensure that software changes can be released quickly and reliably to customers, with minimal risk of errors or downtime.

CD builds on the foundation of Continuous Integration (CI) by extending the automation pipeline to include additional steps such as testing, packaging, and deployment. With CD, code changes that pass all the necessary tests and validations can be automatically deployed to production environments, enabling fast and frequent releases.

CD involves using a range of automated tools and processes to orchestrate the software delivery pipeline, including tools for testing, packaging, and deployment. It also requires a robust infrastructure to support the deployment of code changes to production environments, including tools for monitoring, logging, and alerting.

What is Jenkins Tool?

Jenkins is an open-source automation server that is used for Continuous Integration (CI) and Continuous Delivery (CD) pipelines. It was originally developed as a fork of the Hudson project, and has since become one of the most popular CI/CD tools in use today.

Jenkins allows developers to automate the building, testing, and deployment of their software applications. It can be configured to pull code changes from a shared code repository, build the code using build tools such as Maven or Gradle, run unit and integration tests, and deploy the code to a staging or production environment.

Jenkins is highly customizable and supports a wide range of plugins, allowing developers to extend its functionality and integrate with other tools in their software development workflow. It also has a web-based user interface that makes it easy to manage and monitor the status of builds and deployments.

Jenkins is widely used in agile software development environments, where teams need to deliver high-quality software quickly and continuously. It is also popular in DevOps practices, where it is used to automate the software delivery process and facilitate collaboration between development and operations teams.

Jenkins configuration Setup on EC2

here’s a step-by-step guide on how to set up Jenkins on an EC2 instance:

1. Launch an EC2 instance: Go to the AWS Console, select EC2, and launch a new instance. Choose an Amazon Machine Image (AMI) that has the operating system you prefer. For example, you can choose Ubuntu or Amazon Linux.

2. Configure Security Group: Make sure you create a security group for the EC2 instance that allows access to port 22 (SSH) and port 8080 (Jenkins UI).

3. Connect to the instance: Use SSH to connect to the EC2 instance. You can use the key pair you created while launching the instance.

4. Install Java: Jenkins requires Java to run. You can install Java using the following command:

sudo apt update
sudo apt install openjdk-8-jdk

5. Install Jenkins: To install Jenkins on Ubuntu, use the following commands:

wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt update
sudo apt install jenkins

For Amazon Linux, use the following commands:

sudo yum update -y
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
sudo yum install -y jenkins

6. Start Jenkins: After Jenkins is installed, start the Jenkins service using the following command:

sudo systemctl start jenkins

7. Open Jenkins UI: Open a web browser and go to http://[EC2_Instance_IP]:8080. You should see the Jenkins login page.

8. Install Plugins: Follow the prompts to install any recommended plugins. Alternatively, you can choose to install plugins later.

9. Create an Admin User: Follow the prompts to create an admin user for Jenkins.

10. Configure Jenkins: Once logged in, configure Jenkins as per your requirements. For example, you can configure Jenkins to connect to a version control system, set up build jobs, and configure notifications.

That’s it! Jenkins should now be up and running on your EC2 instance. You can create and build jobs and automate your software delivery pipeline.

Type of Jenkins Jobs

In Jenkins, there are several types of jobs that you can create to automate various tasks in your software development pipeline. Here are some of the most commonly used job types in Jenkins:

  1. Freestyle project: This is the most basic type of job in Jenkins, where you can configure a set of build steps and run them on a schedule or manually trigger them. Freestyle projects are highly customizable and can include any combination of build steps, shell commands, and other plugins.
  2. Pipeline project: This is a more advanced type of job in Jenkins that allows you to define your entire build process as a single script, known as a Jenkinsfile. A Jenkinsfile can be version-controlled along with your application code, and it defines the entire build process, from checkout to testing to deployment. Pipeline projects are highly recommended for complex build processes and continuous delivery.
  3. Multi-configuration project: This type of job is useful when you need to run a build on multiple configurations, such as different operating systems or browsers. You can define multiple configurations, known as axes, and Jenkins will run the build on each combination of axes.
  4. Maven project: If you are using Maven as your build tool, you can use this type of job to build your application. Jenkins will automatically run the Maven build script and produce the output artifacts.
  5. External job: This type of job allows you to run a build script on an external system, such as a remote server or a cloud provider. You can define the build steps and configure Jenkins to connect to the remote system and run the build script.
  6. Matrix project: Similar to multi-configuration projects, a matrix project allows you to run a build on multiple configurations. However, in a matrix project, you define the axes as build parameters, and Jenkins will create a build for each combination of the parameters.
  7. Folder: This is not a job type per se, but a way to organize your jobs into a hierarchy of folders. You can create folders to group jobs by a team, project, or other criteria, making it easier to manage large numbers of jobs.

These are some of the most commonly used job types in Jenkins. Depending on your specific requirements, you may need to use one or more of these job types, or even create your own custom job types using Jenkins plugins.

What’s Next?

We will look into the concepts of each feature listed above and will do small hands-on exercises to understand the implementation of each of those concepts.

--

--

Utsav Desai

Utsav Desai is a technology enthusiast with an interest in DevOps, App Development, and Web Development.