Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

How to use continuous integration with Jenkins on OpenShift

February 28, 2023
Nagesh Rathod
Related topics:
Automation and managementCI/CDContainers
Related products:
Red Hat Ansible Automation PlatformRed Hat OpenShiftRed Hat Quay

Share:

    In this article series, we will set up a continuous integration (CI) pipeline to compile and package a JavaScript game application into a Docker image using Jenkins on Red Hat OpenShift. Once we build the image, it will be pushed to the external Red Hat Quay container registry, Quay.io. When the developer pushes the changes into the Git repository, all these actions trigger.

    This is a series of complete CI/CD pipelines on OpenShift using the Jenkins and Red Hat Ansible Automation Platform. We will cover the following topics:

    • Part 1: Continuous integration with Jenkins on OpenShift
    • Part 2: Continuous deployment using Ansible Automation Platform on OpenShift
    • Part 3: How a manual intervention pipeline restricts deployment

    This article is based on the assumption that you have basic knowledge of Jenkins, OpenShift, and Ansible Automation Platform. You will also need administrator privileges for your OpenShift cluster.

    The CI pipeline architecture

    The developer commits and pushes the changes after initiating the action, as shown in the architecture diagram (Figure 1). Jenkins will detect the changes with the help of polling or webhooks. We build the image in the OpenShift cluster and push it to the Quay.io container registry using buildconfig.

    A diagram of continuous integration architecture.
    Figure 1: A continuous integration architecture diagram.

    Install Jenkins on OpenShift

    Now we need Jenkins Dashboard, which will run the CI pipeline. The easiest way is to deploy a pod of Jenkins on OpenShift from the developer's catalog, as shown in Figure 2.

    A screenshot of the Developer Catalog from where you can install Jenkins.
    Figure 2: Install Jenkins from the Developer Catalog.

    Follow these six steps to install Jenkins on OpenShift:

    1. From OpenShift Web Console, switch to the Developer perspective and navigate to the Topology view. Click on +Add > From Developer Catalog > All services
    2. Search for Jenkins.
    3. Select the persistence Jenkins and install it (For this article, I am keeping the settings as default, but you can modify the settings as per your requirement).
    4. After installation, one Jenkins pod should appear in the project.
    5. To access the dashboard of Jenkins, click on the route icon.
    6. For Jenkins dashboard access, you can use the OpenShift console credential, as shown in Figure 3.
    The Jenkins login screen with OpenShift credentials.
    Figure 3: The Jenkins login screen with OpenShift credentials.

    Set up Jenkins CI pipeline

    The continuous integration stage consists of building and pushing the image into the container registry.

    1. Make sure to have one git repository in place, including the Dockerfile and application dependencies like the requirements.txt file.
    2. Create a Jenkinsfile with the following contents and add this jenkinsfile to the git repository.
    pipeline {
        agent any
    
        stages {
            stage('Hello') {
                steps {
                    echo 'Hello World'
                }
            }
            stage("Checkout") {
                steps {
                    checkout scm
                }
            }
            stage("Docker Build") {
                steps {
                  sh '''
                      #oc start-build --from-build=<build_name>
                      oc start-build -F red-api --from-dir=./api/
                  '''
                }
            }
        }
    }

     

    3. Next, create a BuildConfig file using the following content that will build the source code to executable and push.

    apiVersion: build.OpenShift.io/v1
    kind: BuildConfig
    metadata:
      labels:
        app.kubernetes.io/name: red-api # your application name
      name: red-api # your application name
    spec:
      output:
        to:
          kind: DockerImage
          name: ***************** # add yourimage
      source:
        # Expect a local directory to be streamed to OpenShift as a build source
        type: Binary
        binary: {}
      strategy:
        type: Docker
        dockerStrategy:
          # Find the image build instructions in./Dockerfile
          dockerfilePath: Dockerfile

    Ex: name: quay.io/<username>/cd:latest

    4. Next, create the secrets which will help our build config to push our recently built image in the container registry.

    5. To create a secret, type the following command into your terminal and make sure to use the username and password of your environment. For this exercise, we are using a Quay.io container registry.

    $ oc create secret docker-registry my-secret --docker-server=quay.io --docker-username=xxxx  --docker-password=xxx
    
    
    $ oc secrets link builder my-secret --for=mount

    6. Next, we will create a pipeline from the Jenkins dashboard (Figure 4).

    A screenshot of the Jenkins dashboard.
    Figure 4: The Jenkins dashboard​​​​​ after installation.

    7. Select Pipeline from New Item and give a name to that pipeline.

    8. Select the Build Triggers when the changes are pushed in the GitHub repository.

    9. In the pipeline, select Pipeline Script from SCM.

    10. Fill in the details according to the snapshot shown in Figure 5 for the config we're using for this article.

    Ansible Automation Platform integrate with jenkins pipeline​​​​​​.
    Figure 5: Integrate Ansible Automation Platform with Jenkins pipeline​​​​​​.

    11. Once the pipeline is ready, execute it by clicking the Build Now button. You can see a glimpse of the pipeline in Figure 6.

    A screenshot showing the completed CI stage and the CI pipeline running in the Jenkins dashboard.
    Figure 6: The CI pipeline running in the Jenkins dashboard.

    What’s Next?

    The next article is based on the continuous deployment using the Ansible Automation platform on the OpenShift cluster. You will learn how to install the Ansible Automation platform using the operator’s hub on OpenShift and also the integration of Jenkins and Ansible Automation platform. Check out a demo of this project in DevNation2022.

    Last updated: September 27, 2024

    Related Posts

    • Integrate Continuous Integration with OpenShift Enterprise

    • 5 principles for deploying your API from a CI/CD pipeline

    • How to build cloud-native CI/CD pipelines with Tekton on Kubernetes

    • An introduction to cloud-native CI/CD with Red Hat OpenShift Pipelines

    • Introducing Ansible Molecule with Ansible Automation Platform

    • Get started with Jenkins CI/CD in Red Hat OpenShift 4

    Recent Posts

    • What’s new for developers in Red Hat OpenShift 4.19

    • How to run vLLM on CPUs with OpenShift for GPU-free inference

    • How Kafka improves agentic AI

    • How to use service mesh to improve AI model security

    • How to run AI models in cloud development environments

    What’s up next?

    Get a preview of the Red Hat Certified Engineer (RHCE) Ansible Automation Study Guide (O’Reilly), which covers key Ansible concepts for your system administration needs.

    Get the e-book
    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue