Course · Training · Workshop

Modern Jenkins for CI/CD & Automation

Two days hands-on: develop and test Jenkinsfiles and shared libraries with a fast feedback loop, and manage the Jenkins controller, its plugins and Kubernetes agents as code.

A Jenkins installation consists of Pipelines, shared libraries, plugins and the configuration of the controller and its agents. With Pipeline as Code and Jenkins Configuration as Code all of these parts live in Git: the Jenkinsfile describes the build, shared libraries hold the reusable automation, a YAML file defines the settings of the controller and a Dockerfile defines the Jenkins image with its plugins. Changes are reviewed, tested and rolled out like application code. On the first day you develop Jenkinsfiles and extract reusable steps into a shared Pipeline library that you organize and version. You shorten the feedback loop with local editing and validation: the Declarative Pipeline linter, Replay and a local Jenkins in a container. You write unit tests for Pipeline code with mocked Jenkins steps, and integration tests that run your Pipelines against a containerized Jenkins instance with Testcontainers. On the second day you make the Jenkins installation itself reproducible. You run the official controller and agent images, build a custom Jenkins image and manage its plugins in a plugin list. You define the settings of the controller in YAML with Jenkins Configuration as Code (JCasC), add Groovy hooks where additional flexibility is needed and run builds on Kubernetes agents. Security settings such as authentication and authorization become part of the same configuration. At the end your repository contains the Pipeline, the shared library, their tests and the Jenkins setup, and a change passes the tests before it reaches the production controller.

What participants say

These customers booked courses in the same topic cluster.More customers →

Content

This training is for teams that run Jenkins in production and want Pipelines and a Jenkins installation that are maintainable, testable and reproducible. You work on an example project with a shared library and a Jenkins setup in containers and extend both step by step.

The course consists of the following topics and can be adapted to the audience. The first day covers Pipeline development and testing, the second day the Jenkins installation as code. For in-house courses we agree on the focus areas and the depth of each chapter.

Pipeline fundamentals and practices

  • Pipeline as Code: the Jenkinsfile in the source repository, Declarative and Scripted syntax
  • Pipeline job, Multibranch Pipeline and Organization Folder
  • Readability, maintainability and common pitfalls in Jenkinsfiles
  • Hands-On: set up the environment and extend the Jenkinsfile of the example project

Pipeline developer tools

  • Validate a Declarative Pipeline with the command-line linter over SSH or HTTP
  • Linter integrations for the editor and as a pre-commit hook
  • Replay: modify and rerun a Pipeline run without a commit
  • A local Jenkins in a container with your libraries and Jenkinsfiles mounted from the file system
  • Hands-On: validate and try out Pipeline changes locally before the commit

Shared Pipeline libraries

  • Structure of a library: custom steps in vars, Groovy classes in src, files in resources
  • Global and folder-level libraries, trusted libraries and the Groovy sandbox
  • Load libraries with the @Library annotation and the library step
  • Versioning with branches, tags and commits, and trying out a library change from a pull request
  • Hands-On: extract reusable steps from the Jenkinsfile into a shared library and use it across projects

Unit testing Pipelines

  • Testing frameworks for Pipeline code, with JenkinsPipelineUnit as the example
  • Run Pipeline code in a mock execution without a Jenkins server
  • Mock Jenkins steps and the results of shell commands
  • Test the behaviour of shared library steps and compare the call stack with a reference
  • Hands-On: write unit tests for the Jenkinsfile and the shared library

Integration testing Pipelines

  • Start a containerized Jenkins instance from the test with Testcontainers
  • Test with your own plugin set and initialization scripts
  • Compare unit and integration tests and choose the level for each check
  • Classification: Jenkinsfile Runner as a single-shot Pipeline runner
  • Hands-On: run a Pipeline with the shared library against Jenkins in a container

Jenkins configuration as code

  • Components of a Jenkins installation: controller, agents, plugins, jobs and system configuration
  • Job configuration and system configuration stored alongside the code
  • A Jenkins installation that can be rebuilt from the repository

Jenkins with Docker

  • Run the official controller image jenkins/jenkins with weekly and LTS releases and the official agent images
  • Build a custom Jenkins image with a Dockerfile
  • Manage plugins with a plugin list and jenkins-plugin-cli, pin versions and check for available updates
  • Hands-On: build a custom Jenkins image with your plugin set

Jenkins Configuration as Code (JCasC)

  • Define the settings of the controller in YAML: the sections jenkins, tool, unclassified and credentials
  • Export the existing configuration of a controller as a starting point
  • Pass secrets through variables and secret sources such as Docker secrets, Kubernetes secrets and HashiCorp Vault
  • Apply configuration changes with a reload through the user interface, the CLI or HTTP
  • Hands-On: configure the controller of the example setup, including the shared library, in YAML

Groovy hooks

  • Customize the initialization of Jenkins with Groovy hook scripts in init.groovy.d
  • Combine hooks with JCasC where additional flexibility is needed
  • Hands-On: add a Groovy hook to the custom image

Jenkins on Kubernetes

  • Containerized Jenkins deployments: Helm chart, YAML manifests and Jenkins Operator
  • Kubernetes plugin: one Pod per agent, removed after the build
  • Pod templates in the configuration, with the podTemplate step and as YAML in a Declarative Pipeline
  • Hands-On: run the Pipeline of the example project on a Kubernetes agent

Security as code

  • Define authentication and authorization in the configuration as code
  • Run builds on agents and set the executors of the controller to zero
  • Control the permissions of builds with the Authorize Project plugin
  • Protect the Jenkins home directory and backups, review plugins and container images
  • Follow the Jenkins security advisories and stay on the current LTS line

From change to production

  • One repository workflow for Jenkinsfile, shared library and JCasC YAML
  • Unit and integration tests run before a change reaches the production controller
  • Hands-On: bring a change to the shared library and to the configuration through the tests into the Jenkins setup

At the end of the two days you have an example setup with tested Pipelines, a versioned shared library and a Jenkins installation defined as code with a custom image, JCasC and Kubernetes agents. You know how to bring these practices step by step into your existing Jenkins environment.

The actual course content may differ from the above depending on the trainer, delivery, duration and the composition of participants.

Request this course in-house

By submitting you accept our Privacy Policy.

Request a public date

No suitable public date? Register without obligation — once there is enough interest we schedule a new public date and let you know first.

Number of participants (approx.)

More than 3 participants? Best to request a dedicated in-house date directly.

By submitting you accept our Privacy Policy.

More about Jenkins Pipelines and Configuration as Code

Jenkins Pipeline describes a build, test and delivery flow as code in a Jenkinsfile that is stored in the source repository of the project. Pipelines are written in Declarative or Scripted syntax. Shared libraries hold Pipeline code that several projects use: a library is a repository with the directories vars for custom steps, src for Groovy classes and resources for further files, and it is loaded in a defined version from a branch, a tag or a commit.

Jenkins Configuration as Code (JCasC) defines the settings of a Jenkins controller in a YAML file. The official container image jenkins/jenkins is designed to be extended: a Dockerfile adds the plugins from a plugin list with jenkins-plugin-cli, and Groovy hook scripts customize the initialization. With the Kubernetes plugin, Jenkins runs dynamic agents in a Kubernetes cluster. Together these parts describe a complete Jenkins installation that can be rebuilt from the repository.

Further resources:

Related courses