Skip to content
Examples for jenkins pipelines, comparing scripted and declarative syntax
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Imported kitchen sink example from wildfly. Jul 16, 2017
LICENSE README: Extends example shared libs chapter Dec 31, 2018


This project contains examples for the Jenkins pipeline plugin, comparing both declarative and scripted syntax.

The examples were developed while working on an article series called Coding Continuous Delivery published in Java aktuell. Both English translation and German original can be found on the Cloudogu Blog.

01/2018 (covering examples on branches 1 to 5)
🇬🇧 Jenkins pipeline plugin basics
🇩🇪 Grundlagen des Jenkins-Pipeline-Plug-ins
02/2018 (covering examples on branches 6 and 7)
🇬🇧 Performance optimization for the Jenkins Pipeline
🇩🇪 Performance Optimierung für die Jenkins Pipeline
03/2018 (covering examples on branches 8 and 9)
🇬🇧 Helpful Tools for the Jenkins Pipeline
🇩🇪 Hilfreiche Werkzeuge für die Jenkins Pipeline
04/2018 (covering examples on branches 10 and 11)
🇬🇧 Statical Code Analysis with SonarQube and deployment to Kubernetes et al. with Jenkins Pipelines
🇩🇪 Statische Code Analyse mit SonarQube und Deployment auf Kubernetes et al. mit Jenkins Pipelines

The project being built by the pipeline examples is wildfly/quickstart/kitchensink, a typical JEE web app basing on CDI, JSF, JPA, EJB, JAX-RS and integration tests with arquillian. It was extended slightly to allow for running integration tests using WildFly Swarm and (in branch 11-x) to provide its version name via REST.

The pipeline examples are built on top of each other, each in declarative and scripted syntax, respectively. Each example is put on a separate branches for convenient access.

Please see our Jenkins Instance for build results.

The following aspects are covered by the examples:

  1. A simple pipeline (declarative | scripted)
  2. Improving maintainability by introducing custom steps (declarative | scripted)
  3. Division into smaller stages (declarative | scripted)
  4. End of pipeline a Handling failures (declarative | scripted)
    b Simplified Mailing (declarative | scripted)
  5. Archive and Properties/Options (declarative | scripted)
  6. Parallel (declarative | scripted)
  7. Time Triggered Builds (e.g. nightly) (declarative | scripted)
  8. Shared libraries (declarative | scripted | shared library)
  9. Docker
    a Run whole pipeline inside a Docker container (declarative | scripted)
    b Using Docker inside a custom step (implemented in shared library) (declarative | scripted | shared library)
  10. Statical code analysis with SonarQube
    a check quality gate outside of node (as shown within the docs) (declarative | scripted)
    b analysis and quality gate within one stage (pragmatic, easier to maintain) (declarative | scripted)
  11. Deployment to Kubernetes (declarative | scripted)

Jenkins Setup

All examples (obviously) need the Jenkins Pipeline plugin installed. It has been part of the Jenkins default plugins for quite some time.

8. Shared libraries

Starting with branch 8, the Pipeline: GitHub Groovy Libraries plugin is needed so the libraries are loaded out of the box. It is also one of the Jenkins default plugins.

9. Docker

Branch 9 and up require the Docker Pipeline plugin (installed by default) and only run on workers that have a working docker client (docker binary on the PATH). In order to distinguish this workers from others, they provide a docker label.

10. SonarQube

From branch 10 the SonarQube Scanner plugin and a SonarQube instance set up in Jenkins. In addition, in SonarQube, a webhook to https://JENKINS/sonarqube-webhook must be configured.

11. Kubernetes

In order to deploy to Kubernetes the examples in the 11-x-branches require the Kubernetes Continuous Deploy plugin. The following must be executed (from one of the 11-x-branches) before the build can succeed.

kubectl apply -f k8s/namespace.yaml
kubectl apply --namespace jenkins-ns -f k8s/service.yaml,k8s/serviceaccount.yaml
k8s/create-kubeconfig jenkins-sa --namespace=jenkins-ns > jenkins.kubeconfig

Then, add the jenkins.kubeconfig as Jenkins file credential, called kubeconfig-staging.
Finally, add a Username and Password credential called (e.g. on GCR, the user is json_key and the password is the a JSON in single quotes with line breaks removed!).

Jenkins Build status

Branch Declarative Scripted Library/SQ
1. Simple pipeline Build Status Build Status
2. Custom steps Build Status Build Status
3. Smaller Stages Build Status Build Status
4a Handling failures Build Status Build Status
4b Simplified Mailing Build Status Build Status
5. Archive and Properties/Options Build Status Build Status
6. Parallel Build Status Build Status
7. Time Triggered Builds Build Status Build Status
8. Shared libraries Build Status Build Status Build Status
9a Docker (whole pipeline in container) Build Status Build Status
9b Docker (inside custom step) Build Status Build Status Build Status
10a SonarQube (as shown in docs) Build Status
See SQ!
Build Status
See SQ!
SonarQube Badge
10b SonarQube (pragmatic) Build Status
See SQ!
Build Status
See SQ!
SonarQube Badge
11. Kubernetes Build Status Build Status

Further resources


Shared libraries

A collection of shared libraries to be used as reference.


You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.