OpenShift provides container images for running Jenkins which includes the pre-installed Kubernetes plug-in that allows Jenkins slaves to be dynamically provisioned on multiple container hosts using Kubernetes and OpenShift Container Platform.
To use the Kubernetes plug-in, OCP provides three images suitable for use as Jenkins slaves: the Base, Maven, and Node.js images.
The slaves are pods with will know how to prepare the application, as for example if you have a Java application which is using Maven you need a slave Jenkins pod which is prepared to build the app with Maven. Following an example steps to install Jenkins on OpenShift with a Maven Slave image.
## Create the project where the Jenkins will be installed.
$oc new-project jenkinsmaven –display-name=’Jenkins with Maven slave’
## Create the image stream and build config for your slave Jenkins.
echo "apiVersion: v1 kind: List items: - apiVersion: v1 kind: ImageStream metadata: name: jenkins-maven-slave annotations: slave-label: maven-appdev labels: role: jenkins-slave spec: tags: - name: latest - apiVersion: v1 kind: BuildConfig metadata: annotations: description: Builds Jenkins slave image with maven labels: name: jenkins-maven-slave app: jenkins-slave name: jenkins-maven-slave spec: output: to: kind: ImageStreamTag name: jenkins-maven-slave:latest source: dockerfile: | FROM openshift/jenkins-slave-maven-centos7 USER root RUN yum -y install skopeo apb && yum clean all USER 1001 strategy: type: Docker triggers: - type: ConfigChange" | oc create -f -
Output:
imagestream "jenkins-maven-slave" created buildconfig "jenkins-maven-slave" created
Following the Output of it in the console.
NOTE:
This part will install the Skopeo which can be used to copy images to registries. It is not required and it was just kept in this example to show how to add installed commands for your Jenkins slave pod.
RUN yum -y install skopeo apb && yum clean all USER 1001
##Create a new application with the Jenkins.
$oc new-app jenkins-persistent --param ENABLE_OAUTH=true --param MEMORY_LIMIT=2Gi --param VOLUME_CAPACITY=4Gi
Output:
Following the output of it in the console.
Builds:
Pods:
NOTES
- The “jenkins-persistent” will create a container application where the data will be not lost when the container is restarted. If you would not like to keep the information you can use the “jenkins-ephemeral” instead of it.
- ENABLE_OAUTH=true: It will allow you login into the Jekins with the OCP user/password via OAuth authentication.
- MEMORY_LIMIT and VOLUME_CAPACITY it is to define the resources with will be used by this installation.
## Accessing the Jenkins.
Check the route create for the Jenkins as follows.
### By Terminal
### By console
## Allowing login in Jenkins with OCP OAuth authentication
### Use the router URL to access the Jenkins and click on in the Login with OpenShift
### Add the user/password used in OCP
### Allow the access requested.
Also, it is possible to be done via the OCP catalog as follows.
NOTE: If you are creating a Jenkins to work with NodeJS you should choose another image and don’t use the Maven image slave. You will use the NodeJS image.
For further information check the OpenShift documentation about the Jenkins image