Getting Started with Jenkins

Getting Started with Jenkins

What is Jenkins?

Jenkins is an open-source automation server widely used for continuous integration and continuous delivery (CI/CD) purposes in software development. Its primary objective is to automate the building, testing, and deployment of code changes, facilitating collaboration among development teams and ensuring the timely delivery of high-quality software.

At its core, Jenkins serves as a powerful orchestrator, streamlining various stages of the software development lifecycle. It achieves this by allowing developers to define pipelines, a series of automated steps that transform source code into executable software and deliver it to production environments. These pipelines are configured using code, often written in a domain-specific language called Groovy.

Jenkins supports a plugin architecture, enabling integration with a vast array of tools, technologies, and platforms. This extensibility makes it adaptable to diverse development ecosystems. It integrates with version control systems (such as Git, SVN), build tools (like Maven, Gradle), testing frameworks, containerization platforms (Docker, Kubernetes), and cloud services (AWS, Azure), among others.

One of Jenkins' notable features is its ability to trigger builds automatically whenever changes are pushed to a version control repository. This continuous integration process helps identify and address integration issues early in the development cycle. Jenkins also supports parallel and distributed builds, allowing efficient utilization of resources across multiple servers.

The concept of agents or nodes in Jenkins further enhances scalability and parallelism. Agents can be set up on different machines to execute specific tasks, distributing the workload and accelerating the build and test processes. This distributed architecture makes Jenkins suitable for large-scale projects with complex build requirements.

In addition to CI, Jenkins plays a crucial role in implementing continuous delivery and continuous deployment pipelines. Continuous delivery involves automating the deployment of code changes to staging or pre-production environments, while continuous deployment takes it a step further by automatically deploying changes to production. Jenkins pipelines can be configured to manage these workflows, ensuring a smooth and reliable release process.

Security is a key concern in software development, and Jenkins provides features like role-based access control (RBAC) to regulate user permissions. This helps organizations enforce security policies and restrict access to sensitive information and critical operations within the Jenkins environment.

Jenkins is not limited to traditional software development. Its flexibility allows it to support a variety of use cases, including infrastructure as code (IaC), data pipeline automation, and even mobile application development. Its extensive community and ecosystem contribute to a wealth of plugins, documentation, and best practices, making Jenkins a robust and well-supported tool in the DevOps landscape.

In summary, Jenkins is a versatile and extensible automation server that plays a pivotal role in modern software development workflows. Its capabilities in continuous integration, continuous delivery, and automation make it a valuable asset for organizations striving to enhance the efficiency, reliability, and speed of their software delivery processes.

What is CI/CD in Jenkins:

Continuous Integration (CI) and Continuous Delivery/Continuous Deployment (CD) are integral concepts in modern software development practices, and Jenkins is a popular tool for implementing these processes.

Continuous Integration (CI):

CI involves regularly integrating code changes from multiple contributors into a shared repository. The primary goal is to detect and address integration issues early in the development process.

In Jenkins, CI is often achieved through automated builds triggered by events such as code commits to version control systems (e.g., Git). Jenkins can be configured to automatically pull the latest code, build the application, and run tests.

The CI pipeline ensures that the codebase is always in a consistent and functional state, reducing the likelihood of integration problems that can arise when different developers work on different parts of the code.

Continuous Delivery (CD):

Continuous Delivery extends the principles of CI by automating the process of delivering the application to staging or pre-production environments. The goal is to have a reliable and automated deployment process, making it easier to release changes to users at any time.

Jenkins facilitates Continuous Delivery by defining deployment pipelines that include steps like packaging the application, deploying it to a staging environment, and running additional tests. This process ensures that the application is ready for production deployment but leaves the decision to deploy in the hands of the development or operations team.

Continuous Deployment (CD):

Continuous Deployment takes automation a step further by automatically deploying code changes to production environments once they pass all tests in the CD pipeline.

Jenkins can be configured to implement Continuous Deployment by automating the deployment process to production, reducing manual intervention. However, organizations adopting Continuous Deployment often have strict controls, including thorough testing and monitoring, to ensure the quality and reliability of production releases.

  • Jenkins Pipelines:

    Jenkins Pipelines are a key feature for implementing CI/CD. They allow users to define the entire CI/CD process as code, usually using a domain-specific language called Groovy.

    Pipelines can include stages, steps, and parallel branches, making it possible to orchestrate complex workflows. These pipelines can be version-controlled, providing a clear and reproducible definition of the CI/CD process.

    Jenkins supports both declarative and scripted pipeline syntax, offering flexibility for different use cases and preferences.

  • Integration with Tools:

Jenkins integrates with a wide range of tools and technologies to support CI/CD workflows. This includes version control systems (e.g., Git), build tools (e.g., Maven, Gradle), testing frameworks, containerization platforms (e.g., Docker, Kubernetes), and cloud services (e.g., AWS, Azure).

Plugins play a crucial role in extending Jenkins' capabilities and enabling integration with diverse tools, allowing organizations to tailor their CI/CD pipelines to specific requirements.

How to install Jenkins , Docker in AWS EC2 Ubuntu Machine:

  • Login to AWS Console:

    Go to the AWS Management Console (https://aws.amazon.com/).

    Sign in with your AWS account.

  • Navigate to EC2:

    In the AWS Management Console, navigate to the EC2 service.

  • Launch an Instance:

    Click on the "Instances" in the left navigation pane.

    Click the "Launch Instances" button.

  • Choose an Amazon Machine Image (AMI):

    In the "Step 1: Choose an Amazon Machine Image (AMI)" section, select an Ubuntu AMI. You can search for "Ubuntu" in the search bar and choose an appropriate version (e.g., Ubuntu Server 20.04 LTS).

  • Choose an Instance Type:

    In the "Step 2: Choose an Instance Type" section, select "t2.xlarge" as the instance type.

    Click "Next: Configure Instance Details."

  • Configure Instance Details:

    In the "Step 3: Configure Instance Details" section:

    Set the "Number of instances" to 1.

    Optionally, you can configure additional settings, such as network, subnet, IAM role, etc.

    Click "Next: Add Storage."

  • Add Storage:

    In the "Step 4: Add Storage" section, you can leave the default storage settings or adjust as needed.

    Click "Next: Add Tags."

  • Add Tags:

    In the "Step 5: Add Tags" section, click "Add Tag."

    For "Key," enter "Name" and for "Value," enter "Jenkins" (or your preferred name).

    Click "Next: Configure Security Group."

  • Configure Security Group:

    In the "Step 6: Configure Security Group" section:

    Create a new security group or use an existing one.

    Add inbound rules to allow HTTP (port 80), HTTPS (port 443), and SSH (port 22) traffic.

    Click "Review and Launch."

  • Review and Launch:

    Review your configuration settings.

    Click "Launch."

  • Select Key Pair:

    In the key pair dialog, select "Choose an existing key pair" and choose the "jenkinsandubuntu" key pair.

    Acknowledge that you have access to the private key.

    Click "Launch Instances."

  • View Instances:

    Once the instance is launched, you can view it in the EC2 dashboard.

    Wait for the instance to reach the "running" state.

Setup docker and Jenkins in ububtu:

Go to Ubuntu Machine and update the ubuntu machine:

sudo apt-get update

After that install docker and docker-compose.

sudo apt-get install docker.io docker-compose -y

After that install to the jenkins

sudo apt update
sudo apt install fontconfig openjdk-17-jre
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

After that In docker group add ubuntu and Jenkins and Reboot the Ubuntu.

sudo usermod -aG docker $USER 
sudo usermod -aG docker jenkins
sudo reboot

After that Enable the docker and Jenkins.

sudo systemctl enable jenkins
sudo systemctl enable docker

How to Setup Jenkins in Ubuntu Machine Live: