Repository that explains how to create a custom jenkins image for Openshift (3.4) using Docker Build, S2I and Persistent volumes
OpenShift Jenkins Image Repository: https://github.com/openshift/jenkins
Jenkins is customisable using docker build (example in the directory Dockerfile). To do that, do the following steps:
- Create a Dockerfile that extends the original openshift3/jenkins-2-rhel7
FROM openshift/jenkins-2-rhel7
COPY plugins.txt /opt/openshift/configuration/plugins.txt
RUN /usr/local/bin/install-plugins.sh /opt/openshift/configuration/plugins.txt
- Build the image using the Dockerfile above
docker build -t docker.io/clrxm/custom-jenkins:latest .
- Push the image in a docker registry
docker push docker.io/clrxm/custom-jenkins:latest
- In OpenShift, create a new project
oc new-project custom-jenkins --display-name="Dockerfile Jenkins" --description="Demonstrate custom jenkins image with docker build"
- Create an imageStream with your image (This will import all the tags).
oc import-image custom-jenkins --from=docker.io/clrxm/custom-jenkins --confirm --all
You can repeat this command to import new tags 6. Deploy Jenkins using the OpenShift jenkins template
oc new-app jenkins-ephemeral -p NAMESPACE=custom-jenkins -p JENKINS_IMAGE_STREAM_TAG=custom-jenkins:latest
As it is shown in the section "Latest Openshift Jenkins Image" you can directly build your docker image in Openshift if your dockerfile is available in a git repository.
oc new-build https://github.com/clerixmaxime/custom-jenkins.git \
--context-dir=/Dockerfile --strategy=docker
- Repeat steps 1, 2, & 3 above.
- In OpenShift, create a new project
oc new-project custom-jenkins --display-name="Dockerfile Jenkins" --description="Demonstrate custom jenkins image with docker build"
- Import the custom template under directory Dockerfile
oc create -f https://raw.githubusercontent.com/clerixmaxime/custom-jenkins/Dockerfile/jenkins-docker-image-template.yml
- Deploy Jenkins. You have to specify the JENKINS_IMAGE to use as environement variable
oc new-app jenkins-master-s2i -p JENKINS_IMAGE=docker.io/clrxm/custom-jenkins:latest
You can use the S2I feature of OpenShift to build new Custom Jenkins Images. In order to include your modifications in Jenkins image, you need to have a Git repository with following directory structure:
./plugins
folder that contains binary Jenkins plugins you want to copy into Jenkins./plugins.txt
file that list the plugins you want to install (see the section above)./configuration/jobs
folder that contains the Jenkins job definitions./configuration/config.xml
file that contains your custom Jenkins configuration
Note that the ./configuration
folder will be copied into /var/lib/jenkins
folder, so you can also include additional files (like credentials.xml
, etc.).
- Create a new project.
oc new-project custom-jenkins-s2i
- Build the new custom-jenkins image using S2I jenkins image provided by OpenShift.
oc new-build jenkins:2~https://github.com/clerixmaxime/custom-jenkins.git --context-dir=/s2i --name=custom-jenkins
- Deploy Jenkins using the OpenShift jenkins template
oc new-app jenkins-ephemeral \
-p NAMESPACE=custom-jenkins-s2i -p JENKINS_IMAGE_STREAM_TAG=custom-jenkins:latest
Building the last version of the openshift/jenkins image, an environment variable INSTALL_PLUGINS has been integrated that allows to provide a list of plugins. The image will install all these plugins at start up.
- Create a new project.
oc new-project custom-jenkins-image
- Get image in OpenShift
- Build the image directly in Openshift (This will build the image from a Dockerfile locate on a Git repository and create the ImageStream associated)
oc new-build https://github.com/openshift/jenkins.git \
--context-dir=/1 --strategy=docker
- Import the image in Openshift as an ImageStream (The image has already been built and is available on my Docker Hub. Refer to ttps://github.com/openshift/jenkins to build the image on your own or retag my image and add it to your own registry)
oc import-image jenkins --from=docker.io/clrxm/jenkins-2-centos7 --confirm
- Download the template
jenkins-ephemeral-latest.json
under s2i - Import the template
oc create -f jenkins-ephemeral-latest.json
- Deploy Jenkins using this template
oc new-app jenkins-ephemeral-latest -p NAMESPACE=custom-jenkins-image -p JENKINS_IMAGE_STREAM_TAG=jenkins:latest -p INSTALL_PLUGINS=blueocean:1.0.1
You can also create a custom-jenkins image by mounting a persistent volume with the required plugins.
- Create a Persistent Volume on OpenShift (Depends on your backing-storage solution)
- Copy the required files (
/plugins
directory) in the persistent volume
/!\ The
/plugins
directory must contain all plugin dependencies
- Create a new project.
oc new-project custom-jenkins-pv
- Deploy Jenkins using the OpenShift jenkins-persistent template
oc new-app jenkins-persistent