top of page
hand-businesswoman-touching-hand-artificial-intelligence-meaning-technology-connection-go-

Automating Your Workflow: Setting Up CI/CD with Jenkins and GitHub


Continuous Integration (CI)

    software development practice where team members integrate their work frequently, each person integrates at least once daily which leads to multiple integrations per day . Each integration is automatically verified by building the project and running automated tests against the build, hence it reduces integration problem and allows a team to develop cohesive software rapidly.


All source are kept in a version control system like GIT, accessible to every team member

which facilitates the frequent merging and integration. Project is automatically built, through the process compiling, linking and packaging the code into executable form. To ensure codebase maintains certain level of quality and functionality  automated tests are run as the part of the build process.


Why is this done ?

Because developer get immediate feedback on the integration and testing results, often through automated notification so that they can quickly fix the issues.


Jenkins

Jenkins is an open source automation server used for CI and Continuous Delivery (CD) in software development. It helps automate tasks like building, testing, and deploying code changes, making the development process faster and more reliable.


You should consider using Jenkins because:


It automates repetitive tasks, saving time and effort.

Jenkins supports continuous integration practices, catching bugs early in the development process.

It automates deployment, making software releases more consistent and reliable.

Jenkins is free and open-source, making it accessible to all developers.

It has a large community of users and contributors who provide support and share best practices.


Pros and Cons of Jenkins

Pros:

Open Source: Jenkins is free to use and open-source, providing cost-effective CI/CD solutions.

Community Support: With a large user community, Jenkins offers extensive support resources and a wide range of plugins for customization.

Blue Ocean: The user-friendly Blue Ocean interface improves the Jenkins user experience, making it more accessible to all team members.

Customization: Jenkins allows for extensive customization through plugins, enabling teams to tailor CI/CD pipelines to their specific needs.

Control: Self-hosting Jenkins provides businesses with control over their CI/CD infrastructure and data security.


Cons:

Setup and Maintenance: Setting up Jenkins requires time and expertise, and ongoing maintenance can be complex and time-consuming.

Complexity: Jenkins can be difficult to configure, especially for teams without prior experience, leading to potential setup challenges.

Test Implementation: Writing tests for CI/CD can be time-consuming, and teams may prioritize coding new features over writing tests.

Test Maintenance: Tests require regular updates, adding to the maintenance workload and potentially impacting productivity.

Cultural Shift: Implementing CI/CD requires a cultural shift within the organization, including management buy-in and allocation of time for CI/CD practices.


Continuous Testing in CI/CD

In a continuously evolving development environment where team members regularly integrate code into the repository, maintaining software quality is paramount. Manual testing isn't feasible due to its slow pace and inability to keep up with rapid changes. Automated testing fits seamlessly into CI/CD pipelines, ensuring efficient and effective testing processes. With the CI model's support for parallel testing, issues can be identified early, facilitating prompt resolution and safeguarding software quality.


Prerequisites

GIT installation: Download Git

GITHUB account

Jenkins installation

Plugins:

Maven integration plugin

GitHub integration plugin

Allure Jenkins plugin

Cucumber reports plugin

TestNG report plugin


GIT:

Git is a open source version control system software that allows multiple users to work on same piece of code/file make their own changes and push the changes to project repository on GitHub. Every user can push their code features to either the main or can have their own branches so that the changes can be merged whenever needed.

GIT follows distribution version control system where user can have copy of code on their local computer, they can work on the code offline and push the changes whenever needed. GIT follows distribution version control system where user can have a copy of code on their local computer. They can work on the code offline and push the changes whenever needed.


GITHUB:

GitHub is like a Web based platform provides graphical user interface space ,where you can store your projects and work with others. You can even put stuffs like code, documents, pictures, data file and more. It's not just a place to keep your files, though. You can also use it to work together with teammates by collaborating, review each other's work, and keep track of what needs to be done. Plus, it connects with other tools to help you automate tasks and make your work smoother. Overall, GitHub is a handy tool for managing and collaborating on projects online.


Typical Git Workflow


Lets first understand the workflow of Git .In Git, the workflow typically begins with your project files residing in the working directory, here untracked files will be there ,where using Add command it can be taken to staging area, here we will be having all tracked files, we commit to local git repository. In git repository we have committed files now and we push to remote repository (GitHub) and again the second round starts we clone/pull the code for making changes to local repository(Git) then to the index and working directory. Then, you can continue working on your project, repeating the process as needed to track and manage changes effectively.


STEP-1

Repository Creation:

Create a new repository on GitHub.

Initialize the repository with a README file or start with an empty repository.

Setting Up the Master Branch:


STEP-2

Once the repository is created, Git will automatically create the master branch.

start working directly on the master branch or create additional branches for specific features

STEP-3

Cloning the Repository:

Each team member clones the repository to their local machine using the git clone command followed by the repository URL.


git clone <URL of the repository>


STEP-4

Making Changes:

 If team members makes changes to the project files in their local repository in eclipse,

after making changes, they can use the git status command to see which files have been modified.

To stage the changes for commit, git add command followed by the file name or . to add all changes, can be used


git add .


STEP-5

Committing Changes:

After changes are staged, files get committed to the local repository using the git commit command along with commit message.


git commit -m "message"


STEP-6

Pushing Changes to GitHub:

After committing changes locally, push the changes to the GitHub repository using the git push command.


git push origin master


Configuring Jenkins for GitHub integration:

STEP-1:Global Setup:

Go to the Jenkins dashboard and navigate to "Manage Jenkins" > "Global tool configuration" , add the respective version and installed properties field under the Maven , JDK, Git installation field properties which will be available globally across all Jenkins job. You can skip this step but it will be easier for all Jenkins job ,maintains the consistency and reduce the amount of configuration required for other jobs.

STEP-2:Install Essential Plugins:


Go to the Jenkins dashboard and navigate to "Manage Jenkins" > "Plugins"

In the "Available" tab, search and select the Git plugin, GitHub plugin, and Maven Integration plugin.

Click "Download now and install after restart" and then restart Jenkins to complete the installation.


STEP-3:Create a New Jenkins Job:


From the Jenkins dashboard, click on "New Item" to create a new job.

Enter a name for your job and select "Maven project" as the project type, then click "OK."


Setting Up Source Code Management with Git:


In the configuration page of your Jenkins job, under the "Source Code Management" section, select "Git."

Enter the URL of your GitHub repository in the "Repository URL" field, specify the branch to build.


Configuring Build Triggers:

In the configuration page of your Jenkins job, under the "Build Triggers" section, select the trigger option that suits your workflow.

For example, you can choose to build periodically or trigger builds on GitHub webhook events.


 Create webhooks :

Go to GitHub repository from that settings, click Webhooks and add give Jenkins URL followed by /github/webhook, select the push event checkbox, add webhooks, to receive this GitHub integration plugin is to be added . then in build trigger , check in the GitHub j-hook trigger and save it.




Configuring the Build Environment:

In the configuration page of your Jenkins job, under the "Build" section, you'll find a "Build" tab specific to Maven projects.

Here, you can specify the Maven version to use, as well as any Maven options or goals you want to execute.

Specify the Maven goals you want to execute, such as clean install, in the "Goals and options" field.


Post-build Actions:

In the configuration page of Jenkins job, under the "Post-build Actions" section, you can configure actions to be performed after the Maven build completes.


1.Allure Results: Install and configure the "Allure Jenkins Plugin" to publish Allure results.

2.Cucumber Reports: Add "Publish Cucumber test result report" and specify the JSON report path.

3.HTML Reports: Add "Publish HTML reports" and specify the HTML directory and file paths.



By following these steps, we can effectively set up a CI pipeline using Jenkins and GitHub, ensuring continuous integration and testing of your projects.



53 views1 comment

1 Comment

Rated 0 out of 5 stars.
No ratings yet

Add a rating

Thank you for sharing the article, it is really good and useful. Yes, optimizing the work process will help us complete the work quickly and accurately, like playing Uno Online, we must constantly update the software to optimize the user experience in the best way.

Like
bottom of page