Dark Mode
  • Tuesday, 16 April 2024
DevOps-5: CI/CD [Jenkins]

DevOps-5: CI/CD [Jenkins]

DevOps-5: CI/CD [Jenkins] - Outline

5.1. Learning Objectives

A CI/CD pipeline automates the software delivery process.

Introduction to Jenkins


Some of the CI/CD tools,

Introduction to Jenkins


Jenkins perform different roles,

Introduction to Jenkins


Achieve CI with Jenkins, using Git and Maven

Introduction to Jenkins


5.2. Overview of CI/CD

A CI/CD process automates your software delivery process. Automated pipelines remove manual errors and provide standardized feedback loops.

Introduction to Jenkins

Continuous Integration: It is a development practice in which all development work is integrated as early as possible.

  • Needs to commit the changes at regular intervals
  • Requires regular builds
  • When a code commit occurs, a build should be triggered.

Now, question arise – What tasks must be performed to achieve Continuous Integration?

The list of tasks involved in the Continuous Integration: -

  • Generating and analyzing report
  • Developing and compiling
  • Performing functional test and labeling code
  • Performing unit test
  • Preproduction deployment
  • Database Integration

Advantages of Continuous Integration

  • Monitors the health of your code coverage metrics
  • Reduces technical debts and maintenance cost
  • Publicity visible code quality metrics
  • Automated end-to-end acceptance tests
  • Reduces risk providing faster feedback
  • Helps identify and fix integration and regression
  • Helps simplify and accelerate delivery
  • Automates deployment process

Continuous Delivery: Continuous delivery is an extension of continuous integration. Any successful build can potentially be deployed into production. CD process is not automatic. Business team decides the best time to deliver the latest changes. In the implementation of CD, the goal is to make deployment.

Continuous Deployment: It deploys all the changes in the source code to production automatically without explicit approval from a developer. It is a software release strategy in which each code commit that passes automated testing is automatically sent to production.

Introduction to Jenkins


5.3. Popular CI/CD Tools

It is critical to select the best CI/CD tools for the project’s budget and needs.

Introduction to Jenkins

There are few prerequisites to implement the CI/CD pipeline,

  • Automated build, test, package, and deploy operations.
  • Quick pipeline execution
  • Quick failure recovery
  • Zero-downtime deployment
  • Trunk-based development


5.4. Introduction to Jenkins

Jenkins is an open-source and powerful automation tool that is written entirely in Java. It’s executing a series of action to achieve the continuous integration process and continuous delivery of software projects.

Jenkins community is one of the prime reasons for its popularity. It is not only extensible but it is also having a thriving plugin ecosystem.

Benefits of Jenkins:

  • It is free and cost-effective tool
  • It is a highly portable application.
  • It can be easily installed and configured as per the required needs.
  • It has a very rich plugin library and global community support
  • It can be integrated with limitless other applications and tools

Process of achieving CI with Jenkins:

  • All the commits are built
  • Jenkins CI will check the builds
  • The build is fine, the executable code is ready for deployment
  • The team of developers who will commit changes at regular intervals are notified.

Multiple tools that can be integrated with Jenkins to implements each stage of the CI/CD pipeline:

  • Git, Stash and Visual Studio Code and Commit
  • Docker, Ansible, and others can be used to Build and Configure the application
  • Junit, Cucumber, and others can be user to scan the application for bugs and perform test.
  • Deploy and Serena can be used to release the application tools.

To deploy the application, Cloud Service like AWS, Azure or platform like Openstack can be used.

Bunch of different tasks can be done using Jenkins, like

  • Building – an application
  • Integrating – different components of an application
  • Deploying – an application
  • Reporting – issue in the application
  • Testing – testing bugs in the application

Introduction to Jenkins

How to achieve CI with Jenkins?

It is made sure that all commits are built. Jenkins CI then checks all the builds. The build works, then code is set for the deployment. Build doesn’t function as expected, the development team is notified. They rectify, update and make changes in the code. After its done all the commits are again built and this cycle goes on.


5.5. Setting Up Jenkins

Jenkins is a Java-built open-source Continuous Integration (CI) and CD platform. Basically, Jenkins builds software projects, checks and deploys them.


Hardware Requirements:-

  • RAM- 4 GB (Recommended)
  • Storage- more than 50 GB of Hard Disk Space (Recommended)

Software Requirements:-

  • Java: Java Development Kit (JDK) or Java Runtime Environment (JRE).
  • Web Browser: Any browser such as Google Chrome, Mozilla Firefox, Microsoft Edge.
  • Operating System: An Ubuntu 18.04 server installed with a non-root sudo user and firewall.

Installation Procedure (Linux):-

  1. Check java version
    $ java -version
  2. Install system update
    $ sudo apt update
    $ sudo dpkg --configure -a
  3. Install Java
    $ sudo apt install openjdk-8-jdk
  4. add the framework repository key:
    $ wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add –
  5. Next, link the repository of Debian packages to the sources.list of the server:
    $ sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
  6. When both are in place, upgrade to apt to use the new repository:
    $ sudo apt-get update
  7. Install Jenkins:
    $ sudo apt-get install Jenkins
  8. You can start Jenkins using systemctl:
    $ sudo systemctl start jenkins
  9. As systemctl does not display performance, you can use the status command to check that Jenkins has successfully launched:
    $ sudo systemctl status jenkins
  10. To set up your installation, visit Jenkins on its default port, 8080, using your server domain name or IP address: http://your_server_ip_or_domain:8080

    In the terminal window, use the cat command to display the password:

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

Introduction to Jenkins


Installation Procedure (Windows 10):-



5.6. Integrate Jenkins with Tools Like Git and Maven

Login Jenkin

Introduction to Jenkins


After login, in the dashboard left side, click “Mange Jenkins”,

Introduction to Jenkins


From the list of options choose “Mange Plugins”,

Introduction to Jenkins


You can see the “Updates”, “Available”, “Installed” and “Advanced” tab in the “Plugin Manager” page,

Introduction to Jenkins


In the “Available” tab Search and Install “Git Plugin”,

Introduction to Jenkins



Download git form below url, https://git-scm.com/downloads

Introduction to Jenkins

Download, Install and configure Git to your local sytem.



Download Maven from below url, https://maven.apache.org/download.cgi
Download Binary zip archive(apache-maven-3.8.6-bin.zip)


Extract the folder and put on the C:\Program Files\apache-maven-3.8.6
Set the System Properties>Environment Variable> path into the C:\Program Files\apache-maven-3.8.6\bin


Check maven version by command line and this information will help you in setting up the Global Tool Configuration,



Now back to the Jenkins dashboard, Install the “Maven”



You can see the download and install progress by following,

Jenkins Jenkins


Select the “Global Tool Configuration”,



Configure JDK by following,



Configure “Git” by following,



Configure “Maven” by following,


Now click “Save” to save all “Global Tool Configure”.


5.7. Job Types in Jenkins

You can create new build jobs by clicking on the “New Item” button,



Types of build job in Jenkins,

  • Freestyle Project
  • Maven Project
  • External job
  • Multi-configuration Project
  • Pipeline
  • Folder
  • GitHub Organization
  • Multibranch Pipeline



Jenkins Build Jobs: -

  • Poll SCM: It is also called Source Code Management which involves checking the version control server at regular intervals for any changes that have been committed.
  • Webhook: It helps to transfer real-time data from one application to another, and provide your application a way of consuming new event data from an endpoint.
  • Periodic Builds: It builds the project periodically even if nothing has changed. It might have tests that should be run periodically or an DB clean up Jenkins job or any other Jenkins job.


5.8. Scheduling Jenkins Jobs

Types of Scheduling Jenkins Jobs,

  • Scheduled builds simply trigger your build job at regular intervals
  • This strategy can be used for regular nightly builds.
  • They can be done with something as simple as a simple as Unix cronjob.
  • Continuous integration requires faster feedback than scheduled builds.
  • Scheduled builds can be used for long running build jobs, where quick feedback is less critical.

Jenkins uses cron-style syntax for scheduling the jobs.


Shortcut syntaxes used for scheduling build jobs consist of notations, below are the examples,



5.9. Build Tools and Their Usage

Jenkins requires build tools to integrate the changes made in the source code.
The Advantages of build tools are:

  • Easy Configuration
  • Easy Support
  • Easy Integration

Popular build tools include:

  • Apache Ant:It is a java-based tool. It is mainly used for building java-based application. Ant runs various built-in jobs, such as a compiling, assembly and test.
  • Maven:It is a tool for managing software lifecycles and dependencies. Benefits of maven,
    • It can easily create a project
    • It is consistent across all the projects
    • It can connect a project to a source control system.
    • It can handle multiple projects simultaneously.
    • It follows a standard strategy.
      • Advantages: -
        1. It can be automatically added all of the project’s dependencies.
        2. It can convert a project to war file format easily.
        3. It makes it simple to start a project in a variety of contexts.
      • Disadvantages: -
        1. Maven must be installed on the system before it can be used.
        2. Maven will not be able to add existing dependency if the maven code for it is not available


5.10. Demo - Continuous Integration with Maven

https://github.com/jenkins-docs/simple-java-maven-app Jenkins




https://github.com/bdstar/simple-java-maven-app Jenkins














Now Click “Save”





/**************** START: PROJECT BUILD PART GOES HERE *****************/

/*                                                                                                                     */

/**************** END: PROJECT BUILD PART GOES HERE *****************/

This prove that, maven is successfully integrate with Jenkins.


5.11. Quick Recap
  1. Jenkins
  2. Continuous Integration (CI)
  3. Continuous Delivery/Deployment (CD)




Comment / Reply From