블로그 구독

In this Video

OpenShift provides official Jenkins images that run in containers on OpenShift.

Jenkins is a widely popular and open-source continuous integration and continuous delivery (CI/CD) tool that is used to automate building, testing and deploying application projects. OpenShift provides an official Jenkins image that runs in containers on OpenShift with the OpenShift Pipeline Plugin pre-installed which allows performing actions in OpenShift within Jenkins jobs.

OpenShift 3.2, introduced Jenkins Source-to-Image (S2I) feature which simplifies customization of the official Jenkins image through the S2I build process. You can use Jenkins S2I to copy your custom Jenkins job definitions, additional plugins, or replace the provided config.xml file with your own custom configuration. The resulting image is stored in the OpenShift registry and can be used to deploy pre-configured Jenkins instances.

The Kubernetes Plugin is also pre-installed in the official Jenkins image. This plugins allows Jenkins master to create slave pods on OpenShift and delegate running jobs to them to achieve scalability as well as providing pods with specific runtimes for specific jobs.

This video demonstrates how to use Jenkins S2I and run distributed builds through the Kubernetes Plugin.

Setting Up Jenkins

An example template for using the Jenkins S2I builder as well as creating custom slave images for building Java apps is available on GitHub:

https://github.com/siamaksade/jenkins-s2i-example

Create a new project for Jenkins:

$ oc new-project ci --display-name="CI/CD"

Give the Jenkins pod service account enough rights to be able to make API calls to OpenShift. This allows Jenkins to automatically discover slave images available in the registry.

$ oc policy add-role-to-user edit -z default -n ci

The Jenkins slave template takes any image as an input and layers Jenkins JNLP client on top of it to be used as a Jenkins slave pod. The default parameters turn a RHEL 7 image to a Jenkins slave pod that can run JDK 8 jobs. Import the Jenkins master and slave template:

$ oc create -f https://raw.githubusercontent.com/siamaksade/jenkins-s2i-example/master/jenkins-master-s2i-template.yaml
$ oc create -f https://raw.githubusercontent.com/siamaksade/jenkins-s2i-example/master/jenkins-slave-builder-template.yaml

Create a Jenkins slave image using the Jenkins slave template. You can repeat this step for all slave image types (ruby, python, etc) you need. Image Name is the name of the image you want to convert to a Jenkins slave image and Jenkins Slave Label is the slave label used by Jenkins master to discover slave pods and delegate job to them.

image00

The template defines a build which can be viewed in Browse → Builds section. After build is finished, create the Jenkins master based on the master template via OpenShift Console or CLI:

$ oc new-app jenkins-master-s2i

Running Distributed Builds

Point your browser to Jenkins url as displayed in OpenShift Console and login with default admin user:

Username: admin

Password: password

A build job is already defined by Jenkins S2I based on the job configuration which was provided in the GitHub repo. Click on tasks-build job and then Configure. Check “Restrict where this project can be run” and specify jdk8 for Label Expression.

image0444

Note that Label Expression is how Jenkins finds the slave pods and assigns jobs to them. If you have chosen a different label when instantiating the Jenkins slave template, use the same value in the job configuration.

Start the tasks-build job and note that a slave pod gets created on-demand in OpenShift, runs the jobs and gets removed afterwards.

Conclusion

Jenkins S2I builder simplifies creating custom Jenkins images based on official Jenkins image in OpenShift by providing plugins, job and other configurations in a Git repository. This approach also promotes the infrastructure-as-code principle by applying version control on Jenkins master configurations.
Furthermore, using the Kubernetes Plugin allows running distributed builds at scale and creating Jenkins slave pods on-demand on OpenShift when running Jenkins jobs.


저자 소개

채널별 검색

automation icon

오토메이션

기술, 팀, 인프라를 위한 IT 자동화 최신 동향

AI icon

인공지능

고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트

open hybrid cloud icon

오픈 하이브리드 클라우드

하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요

security icon

보안

환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보

edge icon

엣지 컴퓨팅

엣지에서의 운영을 단순화하는 플랫폼 업데이트

Infrastructure icon

인프라

세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보

application development icon

애플리케이션

복잡한 애플리케이션에 대한 솔루션 더 보기

Original series icon

오리지널 쇼

엔터프라이즈 기술 분야의 제작자와 리더가 전하는 흥미로운 스토리