[OpenShift] – How to install Jenkins on OpenShift?

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 BaseMaven, 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.

Screen Shot 2018-04-20 at 13.13.24

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:

Screen Shot 2018-04-20 at 13.15.57

Following the output of it in the console.

Builds:

Screen Shot 2018-04-20 at 13.17.15

Pods:

Screen Shot 2018-04-20 at 13.16.52

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

Screen Shot 2018-04-20 at 13.20.18

### By console

Screen Shot 2018-04-20 at 13.21.16

## Allowing login in Jenkins with OCP OAuth authentication

### Use the router URL to access the Jenkins and click on in the Login with OpenShift

Screen Shot 2018-04-20 at 13.22.44

### Add the user/password used in OCP

Screen Shot 2018-04-20 at 13.23.26

### Allow the access requested.

Screen Shot 2018-04-20 at 13.23.43

Screen Shot 2018-04-20 at 13.27.46

Also, it is possible to be done via the OCP catalog as follows.

Screen Shot 2018-04-20 at 16.55.47Screen Shot 2018-04-20 at 16.55.55Screen Shot 2018-04-20 at 16.56.07Screen Shot 2018-04-20 at 16.56.43

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s