This Jenkins pipeline provides an example of how to build a basic Spring Boot application using Helm. The pipeline runs using the CoP's jenkins-agent-helm agent and contains the following steps:
Checkout
: Checks out the spring-rest applicationGet Version From POM
: Gets the version defined in the pom.xml file. This version is used to set your image's tag.S2I Build
: Performs an s2i build. This stage runs your unit tests, builds your jar file, and builds your container image. You could split this stage like the basic-spring-boot example if desired, but the jenkins-agent-helm agent doesn't have maven on it, so in this case, it's easier to perform an s2i build instead.Deploy
: Deploys your application to OpenShift.
This pipeline uses two different Helm charts called spring-boot-build and spring-boot. The spring-boot-build
chart is used in the S2I Build
stage to create and update your BuildConfig and ImageStream. The spring-boot
chart is used in the Deploy
stage to create and update your application's Kubernetes resources. While you could combine both of these charts into one, splitting into separate charts for building and deploying provides a greater separation of concerns.
Before you configure this pipeline, you must first build a Jenkins agent containing Helm. Let's look at how you can build the jenkins-agent-helm agent.
While the pipeline itself only uses the spring-boot and spring-boot-build Helm charts, a third Helm chart is provided under the .helm/
folder called jenkins-agent-helm
that you can use to easily build this Jenkins agent. First, install the jenkins-agent-helm Helm chart, which creates a BuildConfig and ImageStream:
helm install jenkins-agent-helm .helm/jenkins-agent-helm
The first build will automatically run. You can follow this build by running:
oc logs bc/jenkins-agent-helm -f
This ImageStream created by Helm already has the role: jenkins-slave
label, so Jenkins will see this and automatically use this image to configure a new Jenkins agent.
Next, let's configure the Jenkins pipeline.
Because the JenkinsPipeline
build strategy is deprecated in OpenShift 4.x, this doc will describe how you can configure this pipeline manually within the Jenkins console.
First, deploy a Jenkins instance to OpenShift. You can deploy Jenkins by running this command:
oc new-app jenkins-persistent
Once Jenkins is up, find and access your route URL:
oc get route jenkins -o jsonpath='{.spec.host}'
Then, follow these steps:
- Click
New Item
on the lefthand side of the screen - Enter a name for this pipeline. The suggested name is
basic-helm-spring-boot
. - Select
Pipeline
and clickOk
- Scroll down to the bottom of the screen to the
Pipeline
section. Change the "Pipeline script" dropdown toPipeline script from SCM
. - For "SCM", select
Git
and enter the Repository URLhttps://github.com/redhat-cop/container-pipelines.git
- For "Script Path", enter
basic-helm-spring-boot/Jenkinsfile
- Click
Save
Once you configure your pipeline, you can click Build Now
on the lefthand side of your screen to start the pipeline.
You can validate your deployment was successful with the following commands:
ROUTE=$(oc get route my-app -o jsonpath='{.spec.host}')
curl $ROUTE/v1/greeting