How To Set Up Continuous Integration With Git and Jenkins?
Tags: testing, tutorial, webdev, programming
Published: 2022-11-22 13:49:38

There are various CI/CD tools such as CircleCI, TeamCity, Bamboo, Jenkins, GitLab, Travis CI, GoCD, etc., that help companies streamline their development process and ensure high-quality applications. If we talk about the [top CI/CD tools](https://www.lambdatest.com/learning-hub/cicd?utm_source=devto&utm_medium=organic&utm_campaign=nov22_pk&utm_term=pk&utm_content=blog) in the market, Jenkins is still one of the most popular, stable, and widely used open-source CI/CD tools for building and automating continuous integration, delivery, and deployment pipelines smoothly and effortlessly.

In this article, we shall explore Jenkins in detail to further understand how it’s widely used for [test automation](https://www.lambdatest.com/selenium-automation?utm_source=devto&utm_medium=organic&utm_campaign=nov22_pk&utm_term=pk&utm_content=blog) of application development tasks, running tests, and final deployment into production. We will then learn how to set up continuous integration with Git Jenkins.

***This [smoke testing](https://www.lambdatest.com/learning-hub/smoke-testing?utm_source=devto&utm_medium=organic&utm_campaign=nov22_pk&utm_term=pk&utm_content=learning_hub) tutorial covers what smoke testing is, its importance, benefits, and how to perform it with real-time examples.***

## Getting Started With Jenkins Continuous Integration

Before starting continuous integration with Jenkins and Git, let us walk through some of the most common terminologies involved in building efficient [CI/CD pipelines](https://www.lambdatest.com/blog/cicd-pipeline-challenges/?utm_source=devto&utm_medium=organic&utm_campaign=nov22_pk&utm_term=pk&utm_content=blog) across various SDLC projects:

 1. Continuous Integration

 2. Continuous Delivery

 3. Continuous Deployment

 4. Source Control Management (SCM)

Let us understand what happens in each of the above stages:

**1. Continuous Integration**

 1. **Continuous Integration**

 2. Building Software implementation in a ‘Development’ environment.

 3. Performing Continuous Dev Testing such as:

 4. Unit Testing

 5. Layout Testing

 6. **Continuous Delivery**

 7. Deploying every developed build on the ‘Staging’ environment.

 8. Performing Continuous Automated Testing such as:

 9. Integration Testing

 10. Visual Testing / Screenshot Testing

 11. System Testing (End to End Testing)

 12. Acceptance Testing

 13. **Continuous Deployment**

 14. Deploying every build on ‘Production’ environment automatically, after passing all tests in Development and Staging environments

 15. **Source Control Management (SCM)**

 16. Contains all the developed source code of the project

 17. Maintains all the current and past state of the code/project

Source Control Management is also referred to as Version Control Software (VCS) and Revision Control System (RCS). While there are several source control management tools available in the industry, Git is the most popular and widely used one as of date, while there are others like SVN, TFS, Mercurial, CVS as well. This is another reason why continuous integration with Jenkins and Git is one of DevOps professionals’ most preferred integrations.

Before getting started with continuous integration with Jenkins and Git, let us dive a little deep into Jenkins and its setup.

## Jenkins Overview

![](https://cdn-images-1.medium.com/max/2000/1*a2U6yLKYgjyux0AxcjDNuw.png)

Jenkins was built by Kohsuke Kawaguchi in 2004 and is one of the [most popular CI/CD tools](https://www.lambdatest.com/blog/best-ci-cd-tools/?utm_source=devto&utm_medium=organic&utm_campaign=nov22_pk&utm_term=pk&utm_content=blog) for continuous integration and continuous delivery. With more than 16,000 stars and 6,500 forks on GitHub, Jenkins is being used by thousands of software companies. Its popularity comes from the fact that it is really good at what it does — building and releasing software pieces. You can refer to our comprehensive [Jenkins tutorial](https://www.lambdatest.com/learning-hub/jenkins?utm_source=devto&utm_medium=organic&utm_campaign=nov22_pk&utm_term=pk&utm_content=blog) for more information.

**Core Concepts of Jenkins:**

**1. Project / Job**

A Project or a Job is a collection of configurable instructions used for building developed source code, testing, collecting artifacts, sending notifications in emails, deploying in required environments, and much more.

**2. Pipelines**

A [Jenkins pipeline](https://www.lambdatest.com/blog/jenkins-pipeline-tutorial/?utm_source=devto&utm_medium=organic&utm_campaign=nov22_pk&utm_term=pk&utm_content=blog) is set of instructions and build steps configured in Jenkins to run all the processes in multiple environments in various steps.

**3. Build Queue and Build Executor Status**

 1. Build Executor Status

 2. Build Queue

![](https://cdn-images-1.medium.com/max/2000/1*CBno8Bo5n--ZUxidSt0CeA.jpeg)

**4. Plugins**

More than 1500 community-contributed plugins in Jenkins support building software varieties, automate tests, and deploy projects for production releases.

**5. Master — Agent**

Executes in remote parallel machines for shorter build and test running time using additional resources in the cloud.

* The master node is usually the machine where Jenkins is configured to be running.

* Agent nodes are generally the other machines that receive instructions from the Master node to help the executions run and finish faster in parallel.

## How to Set Up Jenkins?

Before learning how to set up continuous integration Git Jenkins, you need to set up a Jenkins server in your system. If you already have the setup, you can skip this section and get right to continuous integration with Jenkins and Git. For now, let us walk through the steps by downloading, installing, and configuring Jenkins from scratch.

**How to Download Jenkins?**

**Step 1:** Download Jenkins

Go to the official Jenkins website and download Jenkins.

![](https://cdn-images-1.medium.com/max/2006/1*53dDk20xGQXAv1ytRXldwA.jpeg)

For example, if one has a Windows machine, a jenkins.msi file might start getting downloaded.

While in the case of macOS, one may initiate installing Jenkins via the Homebrew package manager by following the commands provided in instructions on the same page as mentioned above.

**Note:** In this blog, I have taken an example of installing Jenkins on macOS.

**Step 2:** Installing Jenkins on macOS.

Now, let us look at the process of installation of Jenkins locally on a macOS. Let us open the Terminal app in mac and run the below command and wait for the command to install all required tools on the mac machine successfully:

brew install jenkins-lts

Please note that the command shall work only when Homebrew is already pre-installed in the macOS machine. If not installed, kindly install **Homebrew** before running the above command in mac.

**Step 3:** Start Jenkins
Post successful installation of Jenkins, run the following command to start Jenkins:

brew services start jenkins-lts

**Step 4:** Configuring Jenkins as an Admin

Once Jenkins is successfully started, let us validate if the local Jenkins server is starting in the machine by navigating to the following URL in your browser:

```
http://localhost:8080
```

![](https://cdn-images-1.medium.com/max/2000/1*WbozOkKcmHeU2Vqgp3nrfA.png)

Suppose the “**Unlock Jenkins**” web page is displayed after navigating to the above-mentioned URL without an error message. In that case, the Jenkins server is confirmed to be up and running on the local machine.

Copy the above path for Admin Password highlighted in pink in the figure

**Step 5:** Execute the command.

Open Terminal app, and paste the above copied path as provided below:

sudo cat <copied-path>

Example:
sudo cat /Users/skhamaru/.jenkins/secrets/initialAdminPassword

Post successful execution of the above command, the initial admin password can be found displayed as shown in the figure below:

![](https://cdn-images-1.medium.com/max/2000/1*wjhQNSn-feTejPUNqKf8Kw.png)

**Step 6:** Unlock Jenkins

Copy the newly found initial admin password from the terminal and paste it in the “**Administrator password**” field in the previously displayed Jenkins web page, as shown below.

![](https://cdn-images-1.medium.com/max/2000/1*j7hIUm6p2j2NUz71TCWYNA.png)

Then, click on the ‘**Continue**‘ button.

**Step 7:** Customize Jenkins

Click on “**Install suggested plugins**” to install the most common Jenkins plugins.

![](https://cdn-images-1.medium.com/max/2000/1*PI3VHYVB2qvfzcChYfHHnA.png)

**Step 8:** Create First Admin User

Once all the plugins are installed successfully, the first admin credentials will be created for the newly set up Jenkins server.

![](https://cdn-images-1.medium.com/max/2000/1*ud4W7Sjh2dY1DJ3s_skr_Q.png)

Enter valid credentials for the new admin for future configuration changes in Jenkins

**Step 9:** Instance Configuration.

Make sure that the below URL is as per configuration, post which “**Save and Continue**.”

![](https://cdn-images-1.medium.com/max/2000/1*-h_R0Q9THe0rW0PYo8815w.png)

**Step 10:** Complete the Setup

When the page below is displayed, click on the “**Start using Jenkins**” button and explore the newly set up Jenkins server’s user experience.

![](https://cdn-images-1.medium.com/max/2000/1*8OAjLtsOcS_76RG99gNLtg.png)

The newly logged-in admin page shall look as displayed below:

![](https://cdn-images-1.medium.com/max/2000/1*jACGO3BgbofYCUO-PEa2CQ.png)

***In this [system testing](https://www.lambdatest.com/learning-hub/system-testing?utm_source=devto&utm_medium=organic&utm_campaign=nov22_pk&utm_term=pk&utm_content=learning_hub) tutorial, learn why System testing is important and all the intricacies of the System testing process.***

## Setting up Continuous Integration with Git Jenkins

While there are different ways for continuous integration with Jenkins and Git, let us explore the easiest way of integrating using GitHub’s “Personal access tokens” by following the below steps.

## Configuring GitHub for Jenkins Continuous Integration

**Step 1:** Go to your Github profile and navigate to **Settings**.

![](https://cdn-images-1.medium.com/max/2000/1*pYP12pyvEk9x9d5GwiNmCg.png)

**Step 2:** In the settings screen, click on the “**Developer settings**” menu and click on “**Personal access tokens**.”

**Step 3:** In the “**Personal access tokens**” tab, click on the “**Generate new token**” button and provide necessary details as desired (an example is provided in the below figure), and click on the “**Generate token**” button.

![](https://cdn-images-1.medium.com/max/2000/1*UCsb-8zsxfnzDTWhSyt-Rg.png)

**Step 4:** Post successful creation of the token, the newly generated secret text in GitHub is to be copied for future usage in Jenkins.

## Configuring Jenkins for GitHub Integration

**Step 5:** Next, go to Jenkins dashboard.

* Click on “**Manage Jenkins**.”

* Click on “**Configure System**” and go to the following ‘**GitHub**‘ section.

![](https://cdn-images-1.medium.com/max/2000/1*jmkZTc1YDIOaRfn-1h4P1A.png)

**Note:** If the above “**GitHub Server**” section is found missing in Jenkins, make sure to manually install the missing GitHub plugin from the installed list of tools shown below.

Steps to follow- Go to: Jenkins Dashboard -> Manage Jenkins -> Manage Plugins -> ‘Available’ tab -> Enter Git in search bar and filter -> Install required plugin

![](https://cdn-images-1.medium.com/max/2000/1*gAX00AfK2bn__rkmBoH6nw.png)

**Step 6:** Make sure to add the copied secret key in the above credentials by:

* Click on the “Add” -> “**Jenkins**” button in the Github Server section’s Credentials field.

* Select “**Secret text**” from the “Kind” dropdown.

![](https://cdn-images-1.medium.com/max/2000/1*9bH_wkFqyH-9K03XVYXQtA.png)

**Step 7:** Paste the previously copied secret text from GitHub in the **Secret** field as displayed below, while providing an ID such as “jenkins-integration,” and then click on the “**Add**” button.

![](https://cdn-images-1.medium.com/max/2000/1*vU4VTGJ6PqrW_GT_-OW5KA.png)

**Step 8:** Once the Secret text is successfully added, let us test the connection by clicking on the “**Test connection**” button and verify the confirmation message as highlighted below.

![](https://cdn-images-1.medium.com/max/2000/1*jmkZTc1YDIOaRfn-1h4P1A.png)

## Creating Your First Jenkins Job Integrated Into a Test Project

Let us take a sample java project already integrated and configured with the Ant build tool to ease convenience. You can choose any sample project of yours if you like. Let us follow the below steps in Jenkins Dashboard to configure the same.

**Step 1:** Click on “**New Item**” in the Jenkins user interface dashboard on the left side.

![](https://cdn-images-1.medium.com/max/2000/1*6GsMG1gLQcgVMTcmj7_tug.png)

**Step 2:** Let us start with creating a **Freestyle project** in Jenkins for ease of understanding for a beginner. However, we can choose to select any of the following:

![](https://cdn-images-1.medium.com/max/2000/1*Rc1XFNqrAlkC8WuQQumcRQ.png)

Enter a project name in the requested textbox field and select the **Freestyle project** as shown on the image above.

**Step 3:** In the **General** section, check the field “**GitHub project**” and enter a valid Ant project as given below.

![](https://cdn-images-1.medium.com/max/2000/1*SlZCveozu-_pUrs7qFt3uA.png)

**Step 4:** Then, go to the “**Source Code Management**” section and enter the same link as above with an extra .git extension at the end of the URL, as shown in the below screen.

![](https://cdn-images-1.medium.com/max/2000/1*H_QnhVZzmUSXVEyRyt7n1g.png)

**Step 5:** Go to the “**Build Environment**” section and add the following steps shown in the image below. Make sure to add the command in the Targets field under the Ant Build step:

clean compile test package war

![](https://cdn-images-1.medium.com/max/2000/1*eEg1YD7OdwtBnUzsXWNLSw.png)

**Step 6:** Click on the “**Apply**” button and then click on the “**Save**” button.

![](https://cdn-images-1.medium.com/max/2000/1*1kE195OQY1NU-WHL87N-gA.png)

**Step 7:** Once the new Jenkins configurations are successfully saved, the user shall be navigated back to the Project dashboard screen, where the user now clicks on the “**Build Now**” menu on the left-hand side of the displayed dashboard screen.

![](https://cdn-images-1.medium.com/max/2000/1*wOA-ycwp9lqyCIeKxTZcAg.png)

**Step 8:** As the Build has started to run, users shall be able to note the scheduled build running in the “**Build History**” section with a visibly blinking blue round icon. Clicking it will navigate the user to the respective “**Build Status**” page.

Users must click on the “**Console Output**” menu to walk through the build logs generated in the console while building in Jenkins.

![](https://cdn-images-1.medium.com/max/2000/1*Ih1REkUlVy-WpC3TKsdZRg.gif)

## Analyzing JUnit Test Results in Jenkins

Now that we have learned how to set up continuous integration with Git Jenkins and how to create the first Jenkins Continuous integration job within a test project, it is time to take it one step ahead. After creating a job with a Java project, you might also want to analyze the test results. This can also be done using Jenkins.

Let’s see how this can be done for [JUnit](https://www.lambdatest.com/learning-hub/junit-tutorial?utm_source=devto&utm_medium=organic&utm_campaign=nov22_pk&utm_term=pk&utm_content=blog).

**Step 1:** Make sure “**JUnit Plugin**” is already installed in Jenkins.
Go to Jenkins Dashboard -> Manage Jenkins -> Manage Plugins -> Click on the ‘**Installed**’ tab to view all the already installed plugins.

![](https://cdn-images-1.medium.com/max/2000/1*XzWlw2lrv1ePCCbveBmaUQ.png)

**Step 2:** Go to Project -> Click on ‘**Configure**’ -> Click on ‘**Build**’ tab.

![](https://cdn-images-1.medium.com/max/2000/1*Qu8xIyfIbdmrHzG8q9HYkg.png)

**Step 3**: Click on the “**Add post-build action**” button at the bottom of the page.

![](https://cdn-images-1.medium.com/max/2000/1*bPUyNjOTdlTGx2uESf3Vvg.png)

**Step 4:** From the above list of items displayed in the dropdown, select the “**Publish JUnit test result report**” option.

![](https://cdn-images-1.medium.com/max/2000/1*CPExJ3gCATX17zod81aKNg.png)

**Step 5:** Add the generated XML test report XML path from the workspace in the **Test report XMLs** field as shown below.

![](https://cdn-images-1.medium.com/max/2000/1*2QMHP7cZfnKZaTxv44AmWQ.png)

**Step 6:** Click on the ‘**Save**’ and ‘**Apply**’ buttons.

![](https://cdn-images-1.medium.com/max/2000/1*1r76nIYja8hCgEgf8JQN8Q.png)

**Step 7:** Click on the “**Build Now**” button and allow the scheduled build to complete.

![](https://cdn-images-1.medium.com/max/2000/1*Bpoc-ofoTjUY-6vnBh-NWA.png)

**Step 8:** Observe that a “**Test Result Trend**” graph is generated on the project dashboard’s right side.

![](https://cdn-images-1.medium.com/max/2000/1*Kuk2HEIR-CJK6O_HprDRbA.png)

**Step 9:** On closer observation, we can observe that **the x-axis **of the newly generated graph consists of Build Ids, and **the y-axis** is composed of several test cases run in each build.

![](https://cdn-images-1.medium.com/max/2000/1*uwdnajbdrXfJ9Vo2dSufZg.png)

**Step 10:** Along with the generation of test result trend graphs, we can also observe that the “**Latest Test Result**” report is also generated in the dashboard to help users closely analyze the run tests status in each build.

![](https://cdn-images-1.medium.com/max/2244/1*tBU9je309AHxALIORI6ltQ.gif)

## Integrating LambdaTest Automation Plugin

Continuous integration with Jenkins and Git is a great way to streamline your test automation scripts. Furthermore, you can also implement a Jenkins Continuous integration to make your scripts easier to test. LambdaTest provides a [Jenkins plugin](https://www.lambdatest.com/support/docs/jenkins-with-lambdatest/?utm_source=devto&utm_medium=organic&utm_campaign=nov22_pk&utm_term=pk&utm_content=blog) to easily automate your Selenium test scripts by connecting your Jenkins CI instance to [Selenium](https://www.lambdatest.com/selenium-automation?utm_source=devto&utm_medium=organic&utm_campaign=nov22_pk&utm_term=pk&utm_content=blog). If one follows the instructions as provided in the official website of LambdaTest, we can also observe that [LambdaTest integration](https://www.lambdatest.com/integrations?utm_source=devto&utm_medium=organic&utm_campaign=nov22_pk&utm_term=pk&utm_content=blog) works smoothly to the above test run as well on any desired test environment.

![](https://cdn-images-1.medium.com/max/2000/1*WCwlI3mBHzcxUDGbh_hCpA.png)

I simply followed the steps provided on the official website to check how the integration works in Jenkins, and to my surprise, it worked like magic without any extra effort.

![](https://cdn-images-1.medium.com/max/2000/1*P7yPLbX_iBBQMwntkCnKVA.png)

And the tests passed successfully in all the configured test environments!

***A complete [manual testing](https://www.lambdatest.com/learning-hub/manual-testing?utm_source=devto&utm_medium=organic&utm_campaign=nov22_pk&utm_term=pk&utm_content=learning_hub) tutorial covering all aspects of Manual testing, including strategies and best practices.***

## Summary

There is still an ocean left in Jenkins to explore, learn, integrate varieties of plugins, configure builds in several combinations of languages and source code repositories and make the process better with the integration of pipelines in different stages and steps across projects.

Jenkins continuous integration is undoubtedly a one-step gateway for running quicker and automating robust ways to integrate the entire SDLC pipeline stages of build, test, and deploy effortlessly and efficiently by yourself at almost no extra cost. Now take your test scripts one step ahead with continuous integration with Jenkins and Git.

Thanks for reading this article! Leave a comment below if you have any questions. You can always post any questions or queries on [LambdaTest Community](https://community.lambdatest.com/?utm_source=devto&utm_medium=organic&utm_campaign=nov22_pk&utm_term=pk&utm_content=blog) for immediate assistance.