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.
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: adminPassword: 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.
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.
À propos de l'auteur
Parcourir par canal
Automatisation
Les dernières nouveautés en matière d'automatisation informatique pour les technologies, les équipes et les environnements
Intelligence artificielle
Actualité sur les plateformes qui permettent aux clients d'exécuter des charges de travail d'IA sur tout type d'environnement
Cloud hybride ouvert
Découvrez comment créer un avenir flexible grâce au cloud hybride
Sécurité
Les dernières actualités sur la façon dont nous réduisons les risques dans tous les environnements et technologies
Edge computing
Actualité sur les plateformes qui simplifient les opérations en périphérie
Infrastructure
Les dernières nouveautés sur la plateforme Linux d'entreprise leader au monde
Applications
À l’intérieur de nos solutions aux défis d’application les plus difficiles
Programmes originaux
Histoires passionnantes de créateurs et de leaders de technologies d'entreprise
Produits
- Red Hat Enterprise Linux
- Red Hat OpenShift
- Red Hat Ansible Automation Platform
- Services cloud
- Voir tous les produits
Outils
- Formation et certification
- Mon compte
- Assistance client
- Ressources développeurs
- Rechercher un partenaire
- Red Hat Ecosystem Catalog
- Calculateur de valeur Red Hat
- Documentation
Essayer, acheter et vendre
Communication
- Contacter le service commercial
- Contactez notre service clientèle
- Contacter le service de formation
- Réseaux sociaux
À propos de Red Hat
Premier éditeur mondial de solutions Open Source pour les entreprises, nous fournissons des technologies Linux, cloud, de conteneurs et Kubernetes. Nous proposons des solutions stables qui aident les entreprises à jongler avec les divers environnements et plateformes, du cœur du datacenter à la périphérie du réseau.
Sélectionner une langue
Red Hat legal and privacy links
- À propos de Red Hat
- Carrières
- Événements
- Bureaux
- Contacter Red Hat
- Lire le blog Red Hat
- Diversité, équité et inclusion
- Cool Stuff Store
- Red Hat Summit