From the course: Continuous Integration: Tools

Jenkins

The CI tools in the self-hosted category are some of the most capable tools we'll consider. They also give us the most flexibility because we control almost all aspects of the installation, administration, and maintenance. We'll discuss a few tools from this category, starting with Jenkins. When developers think of tools for continuous integration, Jenkins is likely the first to come to mind. It's easily one of the most well-known and widely used automation tools available. More than one million users around the world turn to Jenkins for their automation needs, including continuous integration and delivery. Price is one of the reasons that keep application developers and software engineers turning to Jenkins, its free and open-source. Enterprise support for Jenkins is available through CloudBees, the company founded by the original creator of Jenkins. CloudBees is also one of the largest contributors to the Jenkins open-source project. Jenkins is essentially an automation framework that can be extended through plugins. If the base functionality doesn't cover what you need, there's probably a plugin that can do the job for you. There are nearly 1,500 plugins available in the plugin index. One plugin we'll be using to enhance our pipeline experience is the Blue Ocean plugin. Blue Ocean is actually a collection of plugins that enhances the Jenkins user interface specifically for visualizing pipelines. Jenkins includes a pipeline viewer out of the box, but the Blue Ocean plugin provides a more modern and up-to-date interface. We can model our pipeline in the Jenkins web interface, or with a Jenkins file stored with our code. The Jenkins file format is based on the Groovy programming language, and uses a declarative approach to describe the stages of a pipeline and the actions needed to complete the stage. Let's get started by taking a look at our experimental pipeline as implemented in a Jenkins file. The Jenkins file format is easy to follow, with each configuration element broken out into bracketed sections. At the top, we have an environment block that injects our configuration parameters and AWS credentials into the process running our pipeline. The actual values for the credentials are stored securely in Jenkins to prevent exposure in the repository or log files. Beneath that, we have our stages. I've modeled our experimental pipeline to follow the seven stages used to get the application code and run some quick tests, build a new version of the application, and then deploy and test in the staging and production environments. Each stage contains the steps that run the commands or scripts needed to fulfill the actions for that stage. In the check stage, I've used the parallel directive to tell Jenkins to run the linting and unit tests at the same time. Using parallelization will help speed up the build. Now let's run our pipeline. In the default pipeline view, Jenkins provides a nice visualization of the pipeline, showing each of the stages we've defined in our Jenkins file. However, we can use the Blue Ocean plugin for what I'll call a more aesthetic pipeline visualization. To get to that view, I'll select "Open Blue Ocean". In the Blue Ocean view, our pipeline homepage shows past runs along with results, commit messages, and other details. We also have this handy Run button to start the pipeline process. We could also set up a Webhook with our Git repo so the pipeline runs automatically. But for this demo, I'll just use the Run button. We can also see the stages of our pipeline by clicking into the running job. In this view, we can see each stage of our pipeline along with its status. The green and white checkmarks let us know the stages have passed and the blinking blue icon lets us know which stage is active. The log for each stage is displayed below, and we can expand the form to follow the log in real-time. Now let's wait for the build to finish. The green color in the banner at the top lets us know all stages of the pipeline have completed successfully. With a clear pipeline as code format and extensive plugin library and pipeline visualizations with the Blue Ocean plugin, Jenkins remains a viable tool for continuous integration.

Contents