cloudogu/jenkinsfiles
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 | |
02/2021 (covering example on branch 12, also explains how to do GitOps with Jenkins. See also GitOps Build Lib and GitOps Playground.) | |
π¬π§ CIOps vs. GitOps with Jenkins | |
π©πͺ CIOps vs. GitOps mit Jenkins |
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)
- 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) - 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)
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 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
class Untested
before.
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-oss-deployer
.
Finally, add a Username and Password credential called hub.docker.com-cesmarvin
(e.g. on GCR, the user is _json_key
and the password is the a JSON in single quotes with line breaks removed - cat account.json
).
and change the image name to match your registry.
Jenkins Build status
Further resources
Jenkinsfile
s
- 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)
Shared libraries
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
Others
- jenkinsci/JenkinsPipelineUnit - Unit test for Jenkins pipelines