1. Home
  2. Training Library
  3. Jenkins CICD - Intro

Jenkins Declarative Pipelines

play-arrow
Start course
Overview
DifficultyIntermediate
Duration1h 47m
Students56
Ratings
5/5
star star star star star

Description

Introduction

This training course introduces you to Jenkins, a popular open source tool used to perform Continuous Integration and Continuous Delivery.

We spend time early on reviewing the key Jenkins features and associated terminology. We then take you through a deep dive in configuring Jenkins to perform automated builds using the Jenkins web administration console in hands on demonstrations, ensuring that you become familiarised with Jenkins and how to administer it. We’ll demonstrate features such as:

  • Installing and setting up Jenkins
  • Creating and configuring pipelines manually
  • Creating and configuring pipelines using a Jenkinsfile
  • Configuring Jenkins pipelines using the Blue Ocean interface
  • Defining build execution environments using docker containers
  • Triggering build pipelines, manually and automatically
  • Navigating downstream and upstream build projects
  • Connecting to version control repositories such as GitHub
  • Setting up build pipelines for Java based projects using Gradle
  • Recording artifacts and test results
  • Setting up and scaling out Jenkins with multiple build agents and executors using SSH

Learning Objectives

What you'll learn:

  • The basic principles of build automation as implemented within Jenkins and how should be a applied to manage and maintain building, testing, and deploying your own enterprise software projects
  • How to install, setup, and configure Jenkins pipelines
  • The key differences between Jenkins declarative and scripted pipelines
  • How to manage build artifacts and test results
  • How to scale out Jenkins using Master and Build Agent setups using SSH
  • The benefits of codifying pipeline build instructions using a Jenkinsfile
  • How to leverage Docker containers within a Jenkins pipeline to provide additional build isolation and flexibility
  • How to install and use the newer more modern pipeline centric BlueOcean user interface
  • How to integrate and leverage 3rd party build tools like Gradle, Maven, Yarn, Webpack, and many more within a Jenkins pipeline

Demonstration

This training course provides many hands on demonstrations where you will observe first hand how to use Jenkins to build and release different types of software projects, for example:

  • Building a front end application which has been developed using the React Javascript framework, using technologies such as Webpack and Yarn
  • Building a back end application developed using Java, Gradle, and Docker, requiring Jenkins to compile the source code, packaging it into a WebArchive file, and then finally releasing it into a Tomcat based Docker image complete with Splunk based instrumentation for logging and monitoring

Prerequisites

  • A basic understanding of CICD, or Continuous Integration and Continuous Delivery
  • A basic understanding of software development and the software development life cycle
  • A basic understanding of version control and associated workflows

Intended Audience

  • Software Build and Release Engineers
  • Software Developers
  • DevOps Practitioners

Transcript

- [Instructor] Welcome back! In this lecture, we'll introduce you to the Jenkins Declarative Pipeline syntax. This syntax is perhaps less flexible, but provides a framework for laying out pipeline workflows in an opinionated manner and is quite useful for less complicated pipelines. 

Okay, let's begin. As already briefly mentioned, the declarative pipeline syntax aims to guide you through the process of building your own pipelines. It does so by providing a schema that controls the structure of the pipeline or, from an end user perspective, guides the pipeline author. As seen here in this screenshot, a declarative pipeline is composed of several optional and mandatory sections with some sections embedded in parent sections. A declarative pipeline always starts with a pipeline section, which in turn must contain an Agent and Stages section. The Stages section in turn contains multiple stage sections. Let's now take a quick look at what an actual stripped down basic vision of a declarative pipeline looks like as per the following example. 

Key points of this example are the syntax provides a guiding DSL structure that helps beginners to lay out and structure the pipeline. The script always starts with the pipeline keyword. Using the statement agent any tells Jenkins that the pipeline in all of its stages can be executed on any build agent. The pipeline is composed of three individual stages, build, test and deploy. Each stage may consist of one or many build steps, and in this case, a single step exists per stage. 

Let's now take a closer look at a couple of real world examples using the declarative pipeline syntax. In the first example, we use a declarative pipeline to build a NodeJS application leveraging NPM to perform the core build, test and deployment. Key points within this pipeline script are the tools keyword is used to inform Jenkins how to install the NodeJS tooling on the build agent that the pipeline executes on. In this case, we would have preinstalled the NodeJS Jenkins plugin, and then preconfigured it within the Global Tool Configuration section informing Jenkins how to setup NodeJS tooling to give our pipeline script access to the NPM executable. 

The pipeline script is composed of 4 stages, cloning, dependencies, test, and deploy. The cloning stage performs a git clone of the project source code into the workspace allocated to the pipeline. Each remaining stage executes a corresponding NPM script command. 

In the next example, we again use a declarative pipeline, but this time to build a Java application, leveraging Maven to perform the core build, testing, and docker image packaging and publishing. Key points of this declarative pipeline script are the agent section dictates that the pipeline must execute on a build agent tagged with the docker label. The environment section sets up script variables used later in the pipeline script. The pipeline consists of two stages, build and publish. The build stage overrides and resets the agent that it must execute on, in this case, it leverages a Maven docker container. 

The build stage finishes by running the post section which captures all of the compiled JAR files located in the target subdirectory. Each discovered JAR file becomes a build artifact, which can be referenced in later stages within the same pipeline. The publish stage only executes if the current source control branch is the master branch as specified in the when section. 

Finally, the publish stage incorporates a multi-line step declaration, useful for elongated build scripts. Also, the multi-line build step utilizes string interpolation to reference the previously assigned Image and Version pipeline environment variables.

Okay, go ahead and close this lecture, and we'll see you shortly in the next one.

About the Author

Students9918
Labs26
Courses61
Learning paths14

Jeremy is the DevOps Content Lead at Cloud Academy where he specializes in developing technical training documentation for DevOps.

He has a strong background in software engineering, and has been coding with various languages, frameworks, and systems for the past 20+ years. In recent times, Jeremy has been focused on DevOps, Cloud, Security, and Machine Learning.

Jeremy holds professional certifications for both the AWS and GCP cloud platforms.