Jenkins Continuous Integration With Katalon: A Complete Guide
DevOps significantly changed the software industry. From a siloed process where the focus was entirely placed on development, leaving little to no time to properly test it, to a combination of the two, simultaneously developing testing to shorten the cycle. CI/CD is the key to that innovation, and Jenkins is one of the most popular CI tools on the market.
We’ll learn how to do Continuous Integration with Jenkins in this step-by-step guide.
What is DevOps?
DevOps is a development philosophy combining Development (Dev) and Operations (Ops) team to break down silos between them.
- Dev team is responsible for the coding, scripting, and integrating all of the components needed to create and run the application.
- Operations team is responsible for the provision and management of the infrastructure necessary for development. They also automate deployment pipelines to ensure that application deployments are consistent.
DevOps is possible thanks to the CI/CD pipeline.
What is CI/CD?
At its essence, CI/CD is about frequently building, testing, and integrating little code changes into a shared repository. This approach allows QA teams to test faster, earlier, along with development instead of after development.
- Continuous Integration (CI) is the practice of committing code into a shared repository several times a day. Each commit triggers an automated build process to compile the code and execute the tests.
- Continuous Delivery (CD) is the next phase after CI where the software is delivered to production or staging environment
What is Jenkins?
Jenkins is an open-source automation server widely used for CI/CD pipelines. It allows QA teams to automate the build, test, and deployment processes of their software applications.
Jenkins is highly extensible and supports integration with a wide range of plugins to help users customize its functionality to suit their specific needs.
This flexibility and simple-to-use nature makes Jenkins a perfect fit for building a CI/CD pipeline.
Jenkins Continuous Integration Tutorial
1. Prerequisites
To build a CI/CD pipeline from Jenkins, you first need:
- Java Development Kit
- Knowledge to execute some basic Linux commands
2. What To Do
First, download Jenkins. Read through the guide and choose the suitable package for your needs.
After that, open up a terminal. Enter cd <your-download-directory>
For example, if you have your jenkins.war file in Users/Downloads/Jenkins folder, enter cd Users/Downloads/Jenkins
Next, run this command: java -jar jenkins.war
The Terminal should generate this announcement.
Open your browser and navigate to http://localhost:8080. This is when the Jenkins dashboard appears. Paste your password in to arrive at the Jenkins customization screen.
Once you have set up everything, you should arrive at the Jenkins Dashboard. Click “Create a job” to start.
After that, choose the type of project you want to create. In this case, let’s go with the Pipeline option.
Upon redirection, the configuration page will be displayed.
Let’s see what each option is about:
Option | Benefit |
Description | Provides documentation for the Jenkins job or pipeline, helping users understand its purpose and functionality at a glance. |
Discard old builds | Helps manage disk space usage by automatically removing old build artifacts, ensuring that only the most relevant builds are retained. |
Do not allow concurrent builds | Prevents potential conflicts and resource contention that may arise from running multiple builds of the same job concurrently, ensuring stability and resource efficiency. |
Do not allow the pipeline to resume if the controller restarts | Ensures consistency and reliability by preventing pipeline execution from resuming if the Jenkins controller restarts unexpectedly, reducing the risk of inconsistent states or errors. |
GitHub project | Specifies the GitHub repository URL associated with the Jenkins job or pipeline, enabling integration with GitHub features such as pull requests and webhooks. |
Pipeline speed/durability override | Allows customization of pipeline execution speed and resilience to interruptions, optimizing performance and reliability according to specific project requirements. |
Preserve stashes from completed builds | Maintains stashes created during pipeline execution, facilitating the retention of temporary files and data between pipeline stages for further analysis or processing. |
This project is parameterized | Enables dynamic customization of job parameters, allowing for greater flexibility and reusability across different pipeline executions. |
Throttle builds | Limits the number of concurrent builds, preventing resource exhaustion and ensuring optimal performance by controlling the rate at which builds are executed. |
Build after other projects are built | Establishes dependencies between Jenkins jobs, enabling sequential execution based on the completion status of upstream projects. |
Build periodically | Schedules builds at specific time intervals, automating repetitive tasks and ensuring timely execution of pipeline activities according to predefined schedules. |
GitHub hook trigger for GITScm polling | Automatically triggers builds upon changes pushed to the associated GitHub repository, facilitating real-time integration and continuous delivery workflows. |
Poll SCM | Periodically checks the source code repository for changes and triggers builds if updates are detected, ensuring prompt responsiveness to code changes. |
Quiet period | Introduces a delay before starting a build after changes are detected in the source code repository, allowing time for multiple changes to be submitted before triggering a build. |
Trigger builds remotely (e.g., from scripts) | Enables remote triggering of builds via an API endpoint, facilitating integration with external systems and tools for automation and workflow orchestration. |
After that, you’ll also see the Pipeline section. You can define different stages of your pipeline, such as checkout, build, test, deploy, etc. Each stage represents a logical grouping of tasks within your pipeline. You also have full control over the logic and flow of your pipeline.
Here is a sample Pipeline script:
pipeline {
agent any
stages {
stage('Build') {
steps {
// Checkout source code from Git repository
git 'https://github.com/example/my-project.git'
// Build the project using Maven
sh 'mvn clean package'
}
}
stage('Test') {
steps {
// Run unit tests
sh 'mvn test'
}
}
stage('Deploy') {
steps {
// Deploy the application to a test environment
sh 'kubectl apply -f deployment.yaml'
}
}
}
post {
success {
// Send a notification on success
echo 'Pipeline executed successfully!'
}
failure {
// Send a notification on failure
echo 'Pipeline execution failed!'
}
}
}
This script is a basic CI/CD pipeline that checks out source code from a Git repository, builds the project using Maven, runs unit tests, and deploys the application to a test environment.
Once done, you can click on the Build Now option to run the pipeline and check if it’s successful or not.
You can see the outcome of the pipeline in the stage view.
Integrating Katalon With Jenkins CI
Jenkins supports a wide range of integration. Once you integrate Katalon with Jenkins, you get the best of both worlds.
Katalon offers comprehensive testing, allowing you to test website, desktop, API, and even mobile applications faster, better, and smarter with the help of AI-powered features. Katalon gives you everything you need to plan, write tests, execute tests, manage tests, prepare test data, and generate reports. The rest you need is integrating it into your CI/CD pipeline.
See how you can create Katalon Studio script here:
Once you have all the tests and integrated Katalon with Jenkins, you can execute Katalon Studio tests in Jenkins with Jenkins Pipeline Script (Jenkinsfile).
On the Jenkins Dashboard, click on New Item and create a new Jenkins Pipeline project. From the dropdown list, choose Pipeline Script as the project type.
Copy and paste this command:
For Windows
pipeline {
agent any
stages {
stage('Test') {
steps {
bat """
cd <KRE installed folder>
katalonc -projectPath="<projectpath>" -browserType="<browser>" -retry=<number of retry times> -statusDelay=<seconds> -testSuitePath="<path>" -apiKey="<user API key>" -orgID=<Katalon_OrgID>
"""
}
}
}
}
For MacOs
pipeline {
agent any
stages {
stage('Test') {
steps {
sh '''
cd <KRE installed folder>
./katalonc -projectPath="<projectpath>" -browserType="<browse>" -retry=<number of retry time> -statusDelay=<seconds> -testSuitePath="<path>" -apiKey="<user API key>" -orgID=<Katalon_OrgID>
'''
}
}
}
}
After that, click Save and click Build Now to run the project.