CI/CD stands for Continuous Integration and Continuous Delivery (or Deployment). It is a software development practice in which code changes are automatically built, tested, and deployed to production.
Continuous Integration (CI) refers to the process of frequently merging code changes from multiple developers into a central repository, where automated builds and tests are run to detect integration issues as early as possible. This helps to ensure that the codebase remains stable and bug-free.
Continuous Delivery (CD) takes it a step further by automating the deployment of the tested and verified code changes to a production environment. This allows for rapid and frequent release of new features and bug fixes, with minimal manual intervention.
Together, CI/CD enables development teams to deliver high-quality software more quickly and efficiently, while reducing the risk of errors and downtime.
There are several reasons why CI/CD has become a critical practice in software development
Faster time-to-market: With automated testing and deployment, teams can release new features and bug fixes more quickly, enabling them to respond to customer needs and market changes faster.
Improved software quality: Automated testing and integration checks help catch errors and bugs earlier in the development cycle, reducing the likelihood of defects making it to production and improving overall software quality.
Reduced manual effort: Manual testing and deployment processes can be time-consuming and error-prone. Automating these tasks frees up developers' time and reduces the risk of human error.
Better collaboration: CI/CD encourages collaboration between developers, QA, and operations teams, promoting a shared responsibility for delivering high-quality software.
Scalability: As development teams grow and projects become more complex, manual testing and deployment methods become increasingly difficult to manage. CI/CD helps teams scale their development processes by automating repetitive tasks.
Overall, CI/CD enables teams to deliver software more quickly, efficiently, and with higher quality, while reducing risk and improving collaboration.
Before continuous integrations(CI/CD)
Before continuous integration (CI) became widely adopted in software development, developers would typically integrate their code changes manually, often at the end of a development cycle. This manual integration process was time-consuming, error-prone, and led to a number of issues, including:
Increased integration time: Manual integration processes could take a long time, especially as the codebase became larger and more complex.
Merge conflicts: When developers worked in isolation for long periods of time, they would often make changes to the same parts of the codebase, leading to conflicts that were difficult and time-consuming to resolve.
Increased risk of bugs: With manual integration, it was easy for bugs and errors to slip through the cracks, especially if testing was not thorough or automated.
Delays in the development cycle: Manual integration processes could cause significant delays in the development cycle, as developers waited for others to finish integration before they could continue with their own work.
Increased stress and frustration: Manual integration was often a frustrating and stressful process, as developers struggled to resolve integration issues and meet deadlines.
Continuous integration was developed as a solution to these problems, by encouraging developers to integrate their changes frequently and automatically, rather than waiting until the end of the development cycle to integrate all changes at once. By catching integration issues early and often, continuous integration helps to ensure that the codebase remains stable and bug-free, reducing the risk of delays and increasing the overall efficiency of the development process.
After continuous integrations
After continuous integration (CI) became widely adopted in software development, developers saw a number of benefits, including:
Faster integration times: With automated integration processes, developers no longer had to spend hours or days manually integrating changes.
Fewer integration issues: By integrating changes frequently and automatically, developers were able to catch integration issues early and often, reducing the risk of bugs and errors.
Improved software quality: With automated testing and integration checks, software quality improved, as errors and bugs were caught earlier in the development cycle.
Faster time-to-market: With automated testing and deployment, teams were able to release new features and bug fixes more quickly, enabling them to respond to customer needs and market changes faster.
Better collaboration: Continuous integration encouraged collaboration between developers, QA, and operations teams, promoting a shared responsibility for delivering high-quality software.
Scalability: As development teams grew and projects became more complex, automated integration and deployment processes helped teams scale their development processes more efficiently.
Overall, continuous integration has helped to increase the efficiency and quality of software development, while reducing risk and improving collaboration and scalability.
What is Jenkins?
Jenkins is an open-source automation server that enables developers to build, test, and deploy their software projects. It is a popular tool in the continuous integration and continuous delivery (CI/CD) pipeline, as it allows teams to automate their software development processes and reduce the risk of errors and delays.
Jenkins is a Java-based application that can be run on any platform that supports Java. It provides a web-based interface for configuring and managing jobs, as well as a large number of plugins that extend its functionality. With Jenkins, teams can automate tasks such as building and testing code changes, deploying software to production environments, and notifying team members of build status.
Jenkins is highly customizable, and its plugins allow teams to integrate it with a wide variety of tools and platforms, such as Git, GitHub, Subversion, Maven, Gradle, and many others. Its flexibility and extensibility make it a popular choice for teams looking to automate their software development processes and improve their efficiency and quality.
REAL WORLD SCENARIO
Let's consider a real-world scenario where Jenkins is used in a typical software development workflow:
Version Control: Developers commit their code changes to a version control system like Git.
Continuous Integration: Jenkins is set up to monitor the version control system for changes. Whenever a new commit is made, Jenkins automatically triggers a build process.
Build: Jenkins checks out the latest code from the repository and performs a build process. This typically involves tasks such as compiling the code, running unit tests, and generating build artifacts.
Automated Testing: After the build is successful, Jenkins triggers automated tests. These tests can include unit tests, integration tests, functional tests, and more, depending on the project's requirements.
Code Quality Analysis: Jenkins can integrate with code analysis tools like SonarQube or Checkstyle to perform static code analysis and generate reports on code quality, coding standards, and potential issues.
Artifact Storage: Jenkins archives the build artifacts, including compiled binaries, documentation, and other relevant files.
Deployment: Jenkins can deploy the built artifacts to various environments, such as staging or production servers. This can involve tasks like deploying to application servers, configuring databases, or setting up infrastructure.
Notification and Reporting: Jenkins sends notifications to relevant stakeholders, such as developers, testers, or project managers, about the build status, test results, and any issues encountered. It can also generate reports and metrics for monitoring and tracking the progress of the software development process.
Continuous Deployment: Jenkins can be configured to automate the deployment process to production environments based on predefined conditions and approvals. This ensures that code changes are seamlessly delivered to users without manual intervention.
Monitoring and Scaling: Jenkins can integrate with monitoring and alerting tools to track the performance and health of deployed applications. It can also scale the application infrastructure based on predefined rules or triggers.
Scheduled Jobs: Jenkins allows the scheduling of jobs for recurring tasks such as backups, database cleanups, or periodic maintenance tasks.
By leveraging Jenkins in this scenario, teams can achieve continuous integration, automated testing, code quality analysis, and streamlined deployment processes. Jenkins helps to automate repetitive tasks, ensure code stability, and improve collaboration among team members. Additionally, it provides visibility into the entire software development lifecycle, enabling efficient management and monitoring of the project.
Ways To Install Jenkins on Windows & Linux
--- INSTALL JENKINS ON LINUX METHOD -1 ---
sudo apt update -y
sudo apt install openjdk-11-jre -y
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \
/usr/share/keyrings/jenkins-keyring.asc > /dev/null
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 -y
sudo apt-get install jenkins -y
sudo systemctl enable jenkins
sudo systemctl start jenkins
sudo systemctl status jenkins
--- INSTALL JENKINS ON LINUX METHOD -2 ---
sudo apt update -y
sudo apt install openjdk-11-jre -y
sudo wget https://updates.jenkins.io/download/war/2.387.3/jenkins.war
java -jar Jenkins.war --httpPort=8082
--- INSTALL JENKINS ON WINDOWS ---
Follow these step-by-step instructions to install Jenkins on your Windows machine:
Visit the official Jenkins website at https://www.jenkins.io/ and go to the "Download" section.
Click on the "Windows" tab and download the latest stable release of Jenkins for Windows as a "Generic Java package (.war)" file.
Once the download is finished, navigate to the location where you saved the Jenkins ".war" file.
Open a command prompt by pressing "Win + R" and typing "cmd", then hit Enter.
In the command prompt, navigate to the directory where you saved the Jenkins ".war" file using the
cd
command. For example, if you saved the file in the "Downloads" folder, you would use the command:cd C:\Users\YourUsername\Downloads
.Once you're in the correct directory, run the following command to start Jenkins:
java -jar jenkins.war
.Jenkins will start initializing, and you'll see some log output in the command prompt.
Open a web browser and go to http://localhost:8080/. This is the default URL for accessing the Jenkins web interface.
On the Jenkins web page, you'll be prompted to enter the initial administrator password. To obtain the password, go back to the command prompt where Jenkins is running and look for the line that says "Please unlock Jenkins". Copy the alphanumeric password from there.
Paste the administrator password into the Jenkins web interface and click "Continue".
On the next screen, choose the option "Install suggested plugins" to install the recommended set of plugins. This will enable basic functionality in Jenkins.
Wait for the plugin installation to complete. Once done, you'll be prompted to create an admin user. Fill in the required details and click "Save and Continue".
Finally, you'll see the Jenkins dashboard, where you can start setting up your projects and automation workflows.
That's it! You have successfully installed Jenkins on your Windows machine. Feel free to explore the various features and capabilities offered by Jenkins for continuous integration and delivery.
Jenkins Guide: Installing Plugins, Global Tool Configuration, Configure System, and Adding Credentials
In this guide, we will walk you through the process of installing plugins, configuring global tools, setting up system configurations, and adding credentials in Jenkins. Let's get started!
Installing Plugins
From the Jenkins dashboard, click on "Manage Jenkins" in the left sidebar.
Select "Manage Plugins" to access the plugin installation page.
In the "Available" tab, you can browse and search for plugins you want to install.
Check the box next to the plugin(s) you want to install.
Click on the "Install without restart" button to install the selected plugin(s).
Wait for the installation process to complete. You can view the progress on the Jenkins console.
Once the installation is finished, you may be prompted to restart Jenkins. If required, click on the "Restart Jenkins when installation is complete and no jobs are running" checkbox and then click "Continue
Global Tool Configuration
From the Jenkins dashboard, click on "Manage Jenkins" in the left sidebar.
Select "Global Tool Configuration" to access the tool configuration page.
Scroll down to the section corresponding to the tool you want to configure (e.g., JDK, Git, Maven).
Click on the "Add JDK"/"Add Git"/"Add Maven" button to configure each tool individually.
Provide the necessary details such as name, path, version, etc., depending on the tool you are configuring.
Click on "Save" to save the global tool configuration.
Configure System
From the Jenkins dashboard, click on "Manage Jenkins" in the left sidebar.
Select "Configure System" to access the system configuration page.
Here, you can modify various system-wide settings and configurations.
Review and update the configuration options based on your requirements. Some common configurations include:
Jenkins URL: Set the Jenkins URL to access the Jenkins server.
System Message: Add a system message to display on the Jenkins dashboard.
E-mail Notification: Configure the email settings for Jenkins notifications.
Security Settings: Configure security options like access control, user management, and authorization strategies.
- Click on "Save" to save the system configuration.
Adding Credentials
From the Jenkins dashboard, click on "Credentials" in the left sidebar.
Select "System" to access the system credentials page.
Click on "Global credentials (unrestricted)" or a specific domain to add credentials.
Click on the "Add Credentials" link to add a new credential entry.
Choose the credential type from the available options (e.g., Username and Password, SSH Username with Private Key, Secret Text, etc.).
Fill in the required fields for the selected credential type, such as username, password, private key, etc.
Provide an optional description to help identify the credential entry.
Click on "OK" to save the credential entry.
That's it! You have now installed plugins, configured global tools, set up system configurations, and added credentials in Jenkins. These configurations will enable you to enhance the capabilities of your Jenkins environment and customize it to meet your specific needs.
๐ Start automating your software development workflow with Jenkins! ๐
Jenkins Job Tutorial
n this tutorial, we'll walk you through the process of creating three types of Jenkins jobs: Freestyle, Pipeline, and Multibranch. Each job will have stages for Git checkout, Maven compile, Maven package, and deploying to Tomcat. Let's get started!
Freestyle Job
From the Jenkins dashboard, click on "New Item" to create a new job.
Enter a name for the job and select "Freestyle project" as the job type.
In the job configuration page, go to the "Source Code Management" section and choose your Git repository. Configure the branch or repository URL as per your requirements.
In the "Build" section, click on "Add build step" and select "Execute shell" from the dropdown.
In the shell script section, enter the following commands:
#!/bin/bash
# Git checkout
git checkout <branch_name>
# Maven compile
mvn compile
# Maven package
mvn package
# Deploy to Tomcat
# Replace 'webapp.war' with your generated WAR file name and adjust the Tomcat server details
cp target/webapp.war /path/to/tomcat/webapps/
- Click on "Save" to save the job configuration.
Pipeline Job
From the Jenkins dashboard, click on "New Item" to create a new job.
Enter a name for the job and select "Pipeline" as the job type.
In the job configuration page, scroll down to the "Pipeline" section.
Choose the "Pipeline script" option and enter the following script:
pipeline {
agent any
tools{
jdk 'jdk11'
maven 'maven3'
}
stages {
stage('Git Checkout') {
steps {
// Git checkout
git branch: '<branch_name>', url: '<git_repository_url>'
}
}
stage('Maven Compile') {
steps {
// Maven compile
sh 'mvn compile'
}
}
stage('Maven Package') {
steps {
// Maven package
sh 'mvn package'
}
}
stage('Deploy to Tomcat') {
steps {
// Deploy to Tomcat
sh 'cp target/webapp.war /path/to/tomcat/webapps/'
}
}
}
}
- Click on "Save" to save the job configuration.
Multibranch Job
From the Jenkins dashboard, click on "New Item" to create a new job.
Enter a name for the job and select "Multibranch Pipeline" as the job type.
In the job configuration page, go to the "Branch Sources" section.
Configure the source for your Git repository, such as GitHub or Bitbucket, and provide the necessary credentials and repository details.
In the "Build Configuration" section, click on "Add build step" and select "Pipeline script" from the dropdown.
Enter the same pipeline script mentioned in the Pipeline Job section.
Click on "Save" to save the job configuration.
That's it! You have now created three Jenkins jobs: Freestyle, Pipeline, and Multibranch, with stages for Git checkout, Maven compile, Maven package, and deploying to Tomcat. You can trigger these jobs manually or configure them to run automatically based on your requirements.