Introduction to Jenkins: What You Need to Know

Hey there! ๐ŸŽ‰ Ready to dive into Jenkins? Whether you're new to CI/CD or just need a refresher, this guide will help you get started with Jenkins. Let's go! ๐Ÿš€

Introduction to Jenkins ๐Ÿš€

  • What is Jenkins? ๐Ÿค”

    • Jenkins is an open-source automation server.

    • It helps automate the parts of software development related to building, testing, and deploying, facilitating continuous integration and continuous delivery (CI/CD).

    • Jenkins is an open-source automation for CI-CD

    • Jenkins tools developed using java

    • Jenkins is part of Hudson Project

Initially it is called as Hudson then later it renamed to Jenkins

๐ŸŽฌAbout CI CD

  • CI and CD are two most frequently used terms in modern development practices and DevOps practices

  • CI stands for continuous Integration. It is fundamental DevOps best practices where developers frequently merge code changes to central repository where automated builds and tests runs.

  • CD means Continuous Delivery or Continuous Deployment.

Jenkins is a self-contained, open-source automation server which can be used to automate all sorts of tasks related to building, testing, and deploying software.

๐ŸŒ๐Ÿ”Build and deployment Process

  1. Take latest source code from Repository

  2. Compile source code

  3. Execute Unit tests (Junit)

  4. Perform code Review

  5. Package code as a war file

  6. Deploy the war file into server

Note : All the above builds and deployment tasks can be automated using Jenkins tool.

Key Features of Jenkins ๐Ÿ”‘

  • Extensible: Supports a wide range of plugins for integration with various tools and services.

  • Distributed Builds: Can distribute builds and tests across multiple machines for faster execution.

  • User-Friendly: Provides a simple and intuitive web-based interface.

  • Scalable: Easily scales up for large projects and teams.

Community Support: Boasts a large and active community, providing a wealth of plugins, tutorials, and help.

Why Use Jenkins? ๐Ÿ› ๏ธ

  • Automation: Reduces manual efforts by automating repetitive tasks.

  • Consistency: Ensures consistent build and deployment processes.

  • Speed: Accelerates development and deployment cycles.

  • Quality: Enhances code quality by running automated tests.

  • Integration: Seamlessly integrates with other tools and services.

Prerequisite (Step 1 )

  • Jenkins installation on AWS EC2

  • Create an EC2 instance with ubuntu Linux AMI

  • Connect to your EC2 instance

  • Update all packages by following command :

$sudo apt update -y
  • Install java by following command :
sudo apt install openjdk-17-jdk -y
#choose version and install version accoding to official document which support jenkins

Step 2

Jenkins installation on AWS EC2 Using apt

Add Jenkins to your apt Repository using following command

sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
  https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
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
sudo apt-get update
sudo apt-get install jenkins

Import a key file from Jenkins -CI to enable installation from the package

sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
  https://pkg.jenkins.io/debian/jenkins.io-2023.key
echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc]" \
  https://pkg.jenkins.io/debian binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins

Start and Enable Jenkins Service

$sudo systemctl start Jenkins 
$sudo systemctl enable jenkins 
$sudo systemctl status jenkins

Get the initial administration password

$sudo cat /var/lib/jenkins/secrets/initialAdminPassword

step 3

Open your EC2 instance public IP (https://<public_IP>:8080/) along with port 8080 in your favorite browser. And provide the administration password obtained during the installation.

Note: Make sure you enable 8080 port in Security Group Inbound Rules.

Provided password which we have copied to unlock Jenkins.

Select "Install Suggested Plugins" Card (It will install those plugins )

๐Ÿ›ค๏ธ Creating Your First Job

  1. New Item:

    • Click on New Item in the Jenkins dashboard.
  2. Name Your Job:

    • Enter a name for your job and select Freestyle project.
  3. Configure Your Job:

    • Source Code Management: Link your job to a version control system like Git.

    • Build Triggers: Set when the job should run (e.g., after a commit).Give Build Tigger Periodically

      * * * * *

    • Build: Define the build steps, such as compiling code or running tests.

  4. Save and Build:

    • Save your job and click Build Now to run it.

Note: 5 * stars represents every minute Jenkins Job Should Execute

Configure Below Script as a Build Script

echo "Hello Guys, Divya Here" 
touch divya.txt
echo "Hello Guys, Welcome to learnwithdivya.online" >> divya.txt
echo "Done ..!!"

๐Ÿš€ Tips and Best Practices

  • Backup Regularly: Ensure you have backups of your Jenkins configuration and jobs.

  • Use Pipelines: Pipelines provide a powerful way to define your build process as code.

  • Keep Jenkins Updated: Regular updates bring new features and security improvements.

๐ŸŽ‰ Conclusion

Jenkins is a powerful tool that can supercharge your development workflow. By automating builds, tests, and deployments, it frees up your time and helps you focus on what really matters โ€“ writing awesome code! ๐Ÿง‘โ€๐Ÿ’ป๐Ÿ’ช

Happy building with Jenkins! ๐Ÿš€โœจ

Here my POC Results for you :

CLI output Jenkins Started

Creation 1st job

Console Output

Build got succuss

0
Subscribe to my newsletter

Read articles from Divya vasant satpute directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Divya vasant satpute
Divya vasant satpute

, I'm a seasoned DevOps engineer ๐Ÿ› ๏ธ with a knack for optimizing software development lifecycles and infrastructure operations. ๐Ÿ’ก Specializing in cutting-edge DevOps practices and proficient in tools like Docker, Kubernetes, Ansible, and more, I'm committed to driving digital transformation and empowering teams to deliver high-quality software with speed and confidence. ๐Ÿ’ป