Jenkins Automation for High-Quality Builds
February 7, 2022

Jenkins Automation: What It Is & How It Works

Open Source Automation

Jenkins is an easy-to-use, Java-based, open-source, and plugin-rich continuous integration (CI)  and continuous development (CD) tool.

Many organizations today use Jenkins automation to build and test their software development projects continuously in their CI/CD pipeline. This blog post will explain how Jenkins works and why you should use Jenkins automation for agile software development.

Back to top

What is Jenkins?

Jenkins is a CI/CD tool that leverages automation and many testing and deployment technologies to accelerate the software development process. By automating different phases of the SDLC, Jenkins enables developers to learn about errors in their code at an early stage and deploy quickly.

As a result, Jenkins helps organizations adopt DevOps practices.

Jenkins supports all environments, including on-premise, cloud, and hybrid. Its support for cloud environments is particularly notable because it gives developers more web development options, including building cloud-native applications.

Jenkins provides continuous build, testing and deployment of software packages. The following is an example of use cases developers can use Jenkins for:

1. Builds can be started automatically when new code is committed to version control (frequent daily builds). These are typically used for unit tests (e.g., for Nightly Builds).

2. Builds can be performed on demand by developers who want to verify that their feature/bug fix works without having to wait for the next scheduled build (e.g., "Cron" mode). This may use more than one machine so as not to slow down development.

3. A build can be scheduled to run only during the hours when the development team is usually active. This avoids wasted runs of builds at times when the development team may not be around.

4. Continuous Deployment - Jenkins supports a continuous deployment model where code changes are automatically tested and deployed as soon as they pass all specified criteria. This reduces human involvement and minimizes possible human errors. 

Jenkins handles software projects of any size, from small teams to large organizations across various industries with ease. It has been successfully used by government agencies, financial institutions, healthcare providers, large media companies and many more, for different use cases such as application build, release management and deployment automation.

đź“• Related Resource: Learn more about Government + Cloud: How IT Government Agencies Can Safely Migrate to Cloud

Let’s explore and discuss the various processes involved in the Jenkins pipeline to take a closer look at how Jenkins works.

Back to top

Jenkins Automation Pipeline: An Overview

The Jenkins automation pipeline is the steps required to get a project from version control, through testing and all additional stages before it is finally deployed. The Jenkins Pipeline refers to Jenkins' ability to automate the complete build-test cycle, through a sequence of plugins that support the implementation of continuous integration and continuous delivery. 

The pipeline itself can be defined by the Jenkins user, making it easy to create custom steps for each client or development team. This allows developers to develop several versions of their application at once and keeps all changes organized and separated.

Developers can then set up Jenkins to automatically build and deploy each version of the application after checking in code changes worked on by developers. Any change to an application goes through what's often a complex sequence of jobs, tasks, and events before it can be released. This approach ensures that developers never push code changes unless they work as intended, reducing potential problems with later stages of the pipeline.

The Jenkins automation pipeline includes the following:

Commit

Whenever several developers work on the same project, they often edit the same files, and mistakes inevitably happen. Backing up only the latest copies of the files is often not enough to undo a problem that one of the developers may have made to the code. This is where Jenkins' "Code Commit" stage comes into play.

The Code Commit step of the pipeline scans through all files committed to version control and detects any file changes done by developers. If they detect any errors in the code - such as if two different developers modified the same line of code or deleted some necessary text - it sends an automated build failure notification to the developer who made the changes. This is helpful because it gives developers a chance to recover with minimal disruption to other processes in the pipeline.

Other testing tools often just notify you when tests fail. However, that approach does not alert the developer who introduced the error in question, which can put an application at risk of being released with a major bug that could have been caught and fixed early on.

In the commit stage, developers use Git, Subversion, Mercurial, and other version control software. The software allows developers to try out experimental features without breaking the codebase.

Jenkins detects when developers make changes to the code and sends a notification to the developer who made the change. Developers can undo their own changes easily, by rolling back to the latest working version of the code. 

Build

Build in the Jenkins pipeline refers to the putting together of individual coded components from developers to create deployable programs that can run on a machine. This compilation process is critical to the software development process because it is during this stage that source code files are combined to make executable code. Builds are often created when the source code is considered ready for implementation— it's either ready for release or testing.

A typical build will contain:

  • A compilation of source code files
  • Linking of object code
  • Generation of source-code embedded documentation like Javadoc and Doxygen
  • Installers (distribution packages production)
  • Automation tests execution, including tests like performance tests, static analysis tests and static tests
  • Generation of source-code embedded reports that tell programmers how many errors and warnings happened during the build
  • Distribution packages deployment

Test

Testing in the development process involves scrutinizing the smallest parts that can be tested to see if they're operating as designed. These tests are often automated and help developer teams find bugs in their applications. Tests help developers avoid releasing to end users sub-standard code.

Some of the tests that are run include:

  • Unit testing
  • Integration testing 
  • End-to-end (functional) testing
  • User acceptance testing (UAT)
  • Performance testing

Some development teams include manual QA by having a tester or QA specialist manually verify the application. This is an inefficient process because it only tests the user interface and does not test for core functionality like performance issues and security holes. 

Staging

The staging environment is a mirror image of a production environment. It is a replica of the final release environment, so all tests and fixes created in the development process can be automatically put into practice on this server. This is also where automated test cases from Jenkins are run.

If problems are identified on staging, they can go back to the developers for fixing before making it to the final release. DevOps personnel can also run manual tests on this environment to see if everything worked as expected and identify any significant changes that need to be made.

The staging server should only contain the bare minimum of application infrastructure needed for testing, such as service accounts or access keys because it's meant only for testing and not for use by end-users.   

Deliver/Deploy

Deploy refers to taking all artifacts of an application development process and copying them into a server or executing them on a server. The deployment process is pretty straightforward and is considered the last stage of the software development lifecycle (SDLC). It involves compiling the project and publishing the output. In this stage, Jenkins simply copies the final product to a server.

Back to top

How Jenkins Works: Jenkins Architecture

Jenkins automation pipeline architecture

The Jenkins architecture explains how Jenkins works with the various elements coming together and interacting:

  1. Development - Programmers commit all changes to the source code that's in the repository.
  2. Code repository - Stores the developers' code, including archives of all changes that have ever been made to that code.
  3. CI server - Regularly checks the code repository and pulls any new code that's been added.
  4. Build server - Compiles all the source codes into executable files. If the build fails, it sends feedback to the developers to make the necessary changes to their code.
  5. Test server - Jenkins tests the build application by deploying it to the test server. If the build fails the test, the programmers are notified.
  6. Production server - If there are no errors in the code, the application, having passed all tests, is deployed here.

Primary/Secondary Architecture in Jenkins

In most scenarios, a single Jenkins server doesn't meet all the needs of an application development process; it can't handle multiple builds and files simultaneously. Typically, numerous distinct environments are needed where builds can be tested. Also, for heavier, more extensive projects, one Jenkins server would quickly be overwhelmed.

A distributed Jenkins architecture uses a primary-secondary architecture to manage distributed builds. The setup uses the TCP/IP protocol for communications between the Primary and the Secondary servers.

Jenkins Primary

The Jenkins Primary server operates as the control server orchestrating all the pipelines' workflows. It schedules jobs, assigns secondary servers, sends builds to secondary servers, and keeps track of the state of all the secondary servers both online and offline. It also retrieves all build result responses and displays them on the console's output. The primary server holds all key configurations.

Jenkins Secondary

A Jenkins Secondary refers to a Java executable running on a remote server. The Jenkins Secondary server is designed to be compatible with most operating systems and follows all the requests from the Jenkins Primary. It executes all the build jobs it receives from the Jenkins Primary server. Jenkins picks whichever available Secondary onto which to send requests, but you can configure the system to choose specific Secondary machines to run particular projects.

Back to top

Jenkins Automation and Continuous Testing 

Before Jenkins became commonplace in software development circles, development teams used nightly builds in their software delivery processes. Team members would commit the code they had been working on throughout the day to the source code repository, and run them overnight to identify errors. The next day, the development team would try to resolve the errors, often without knowing who's commit broke the build. This process took a long time and often resulted in many lost hours of productivity.

Jenkins takes an entirely different approach: it can be triggered to build with every commit sent to the source code repository and run tests in a continuous manner, when triggered. Jenkins uses automated tests like functional, performance, regression, integration tests and load tests to achieve continuous testing. Automation makes it possible for these tests to be carried out as soon as individual developers' code is ready, whichever stage of the pipeline they are. 

In scenarios where the tests fail, the developer whose commit failed the test receives a notification and works to correct their code. If all commits pass the tests, the build pipeline proceeds to the next phase.

Automation eliminates human involvement, and with it, reduces bottlenecks and dependencies. In addition, automation increases speed, lowers costs, and reduces the human errors that stem from repetitive work. In today's tech landscape, new versions of software and applications are being released to users practically every day, including new browser versions, operating systems, device resolutions, etc. Any competent development team must keep up with such changes to offer their users the best user experience when accessing and using their application.

Back to top

Advantages of Jenkins Automation Testing

The following is a list of benefits that DevOps teams can enjoy by using Jenkins automated testing:

  • Small changes are easily handled - the smaller the change, the less a developer wants to wait for a build. Automated testing can run tests needed for a small change in seconds.
  • Easier test automation prioritization -  QA teams no longer need to spend time prioritizing the testing needed for a new feature or bug fix. Automated testing allows the tests to be run as soon as developers check-in their code.
  • Easier continuous delivery - with Jenkins, software updates are automatically tested and deployed as soon as they pass all specified criteria. This reduces human involvement and minimizes possible human errors.
  • Faster regression testing -  with Jenkins, automated testing typically takes place as part of the continuous integration process, allowing regression tests to be executed quickly after every software change.
  • Testing is not intrusive - Jenkins does not require developers' access to be limited for test automation purposes. QA teams can define what they want to automate and Jenkins will take care of the rest. 
  • Code coverage - Jenkins also supports unit testing. Automated tests can be run up-front during the development process to support TDD (Test Driven Development). This ensures that all new code is covered by automated test cases, helping developers write better code.
  • Faster QA feedback to the dev team - with Jenkins, developers can run automated tests themselves using nodes that are set up for the purpose. This allows them to get immediate feedback on the changes they have made and catch any potential issues before checking in their code.
  • Ensuring quality software - Jenkins runs the full spectrum of automated tests, including unit tests and integration tests. This helps catch issues early in the development cycle that would otherwise end up causing problems down the line when the application is used by end-users.
  • Test-scheduling - Jenkins includes scheduling functionality allowing testers to schedule specific tests to run whenever they specify. This is a more convenient, time-saving approach.
  • Developer-focused - Jenkins was created for developers and by developers and therefore has the features developers would need, and that function as developers would expect. As a result, developers using Jenkins can focus on bringing their innovations to life instead of the repetitive, time-consuming testing processes.
  • Open source - because Jenkins is open source, it's available to everyone. The Jenkins community is also very active, so there are plenty of resources for questions developers might have about how to get started with Jenkins or best practices for using it.
  • Reports - The display of test results summary and trends gives users an in-depth look into the automated tests and how well they were executed. Testers can see the trends of the automated tests, including failure points of previous builds, the length of time it took to run various tests, etc. Such information goes a long way in helping users improve the pipeline.
Jenkins Test Maven Report
Back to top

Bottom Line

Jenkins has become the choice framework for developing and testing new codes for a growing number of developers. It's making it possible for developer teams to avoid log jams and costly delays. The result has been better quality applications and faster delivery — shorter software products' time-to-market.

Try testing Jenkins with BlazeMeter today.

START TESTING NOW

 

Related Resources

Back to top