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)|
|02/2018 (covering examples on branches 6 and 7)|
|03/2018 (covering examples on branches 8 and 9)|
|04/2018 (covering examples on branches 10 and 11)|
|02/2021 (covering example on branch 12, also explains how to do GitOps with Jenkins. See also GitOps Build Lib and GitOps Playground.)|
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:
- A simple pipeline (declarative | scripted)
- Improving maintainability by introducing custom steps (declarative | scripted)
- Division into smaller stages (declarative | scripted)
- End of pipeline
a Handling failures (declarative | scripted)
b Simplified Mailing (declarative | scripted)
- Archive and Properties/Options (declarative | scripted)
- Parallel (declarative | scripted)
- Time Triggered Builds (e.g. nightly) (declarative | scripted)
- Shared libraries (declarative | scripted | shared library)
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)
- 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)
- Plain Deployment to Kubernetes (declarative | scripted)
- Deployment to Kubernetes using Helm (declarative (TODO) | scripted)
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.
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
In order to distinguish this workers from others, they provide a
From branch 10 the SonarQube Scanner plugin and a SonarQube instance
sonarcloud.io set up in Jenkins.
In addition, in SonarQube, a webhook to
https://JENKINS/sonarqube-webhook must be configured.
Before Jenkins is able to analyse the branches a first analysis has to be done (e.g. from your developer machine) analysis, e.g. like so
mvn clean install -Pjenkins -DskipITs mvn sonar:sonar -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=<SECURITY TOKEN> -Dsonar.organization=<YOUR-ORG-KEY>
If you want the quality gate to fail (for showcases), one option is to analyse one of the 10a branches but remove the
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
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 -
and change the image name to match your registry.
Jenkins Build status
- triologygmbh/test-data-loader - Deploys to maven central
- cloudogu/continuous-delivery-docs-example - Docs as code to ODT & PDF
- cloudogu/continuous-delivery-slides-example - Deploy presentations to Kubernetes and Maven Sites (Nexus)
A collection of shared libraries to be used as reference.
- cloudogu/ces-build-lib - Contains features for Maven, Docker, SonarQube and others
- mozilla/fxtest-jenkins-pipeline - used by Firefox Test Engineering
- docker/jenkins-pipeline-scripts - helper functions and classes used by Jenkins instances managed by Docker, Inc.
- fabric8io/fabric8-pipeline-library - reusable Jenkins Pipeline steps and functions to be used with the fabric8 platform.
- Mirantis/pipeline-library - Contains Salt commands, Git actions, Artifactory management, Docker image building, AWS and OpenStack provisioning, etc.
- Shared Library Demo - Demonstrates a continuous delivery pipeline of Java web application including library
- jenkinsci/JenkinsPipelineUnit - Unit test for Jenkins pipelines