OpenShift provides a Jenkins Container as the CI/CD tool to run on an OpenShift cluster. You can use this tool to set up your CI/CD pipelines in order to deploy applications to an OpenShift cluster or elsewhere. However, we do come across use cases where there is a need to run Jenkins outside OpenShift and still deploy applications to an OpenShift cluster. For example, some organizations have invested in CI/CD infrastructure that they want to reuse for workloads deployed to OpenShift.
There are a few ways to use an external Jenkins to deploy applications to OpenShift:
- You can install an
oc
command line tool on the external Jenkins server and useoc
mechanism to deploy applications to OpenShift. - You can use REST APIs to interact with OpenShift.
- You can use OpenShift plugin to deploy applications to OpenShift.
In this post, we'll focus on the third option.
Step 1: Install Pipeline Plugin
On your Jenkins console, go to "Manage Jenkins" option and "Manage Plugins." Search for OpenShift Pipeline Jenkins Plugin in the "Available" tab and install it.
Note: Make sure that the Jenkins Pipeline Plugin is installed.
Now we are ready to set up a pipeline.
Step 2: Set up a Pipeline
Now go to Jenkins Home and add a "New Item" on the left menu. Input a value for the field "Enter an item name" and choose "Pipeline" and press OK. On the next page:
- Add a "Description" (this is optional).
- Check the box for "This project is parameterized." It will display the Add Parameter button. Add the following parameters:
- String parameter named
KUBERNETES_SERVICE_HOST
and set the Default Value as your OpenShift host URL. - Boolean parameter named
SKIP_TLS
checked by default. - Password parameter named
AUTH_TOKEN
set to your token value. You can login to the same OpenShift server usingoc login
on your workstation and runoc whoami -t
to get the token value to use here.
- String parameter named
- Scroll down to the end and add the pipeline script in the
Pipeline
section. For this exercise, we will use the following example script:
node('') {
stage 'buildInDevelopment'
openshiftBuild(namespace: 'development', buildConfig: 'myapp', showBuildLogs: 'true')
stage 'deployInDevelopment'
openshiftDeploy(namespace: 'development', deploymentConfig: 'myapp')
openshiftScale(namespace: 'development', deploymentConfig: 'myapp',replicaCount: '2')
}
This script has two stages:
- In the
buildInDevelopment
stage, it starts a build by invoking the build configuration namedmyapp
in the project nameddevelopment
using theopenshiftBuild
step. - In the
deployInDevelopment
stage, it deploys using the deployment configuration namedmyapp
using theopenshiftDeploy
step. Then it scales up the application to 2 replicas using theopenshiftScale
step.
The documentation for these steps from the OpenShift Jenkins Pipelines plugin is available here. I recommend exploring all the possibilities.
Step 3: Create the Build and Deployment Configurations
Because we are trying to use build and deployment configurations in the project named "development" from the pipeline, we will have to first create those following these steps:
- Create a project named "development" from the web console
- Add to project an application (for example, use PHP latest)
- Name the application "myapp"
- Provide a Git URL for source code (for example, https://github.com/openshift/cakephp-ex.git)
- Click on advanced options
- Uncheck the three options under "Build Configuration:"
- Configure a webhook build trigger
- Automatically build a new image when the builder image changes
- Launch the first build when the build configuration is created
- Uncheck the two "Autodeploy" options under "Deployment Configuration"
- New image is available
- Deployment configuration changes
Step 4: Start the Pipeline
Now go back to Jenkins and start the pipeline. Observe build, deployment, and scale up on the OpenShift web console while the pipeline stages are executed in the Jenkins console.
Summary
In this article, I showed how to set up a external Jenkins to talk to an OpenShift cluster using Jenkins Pipeline plugin and described how to use it.
About the author
More like this
Browse by channel
Automation
The latest on IT automation for tech, teams, and environments
Artificial intelligence
Updates on the platforms that free customers to run AI workloads anywhere
Open hybrid cloud
Explore how we build a more flexible future with hybrid cloud
Security
The latest on how we reduce risks across environments and technologies
Edge computing
Updates on the platforms that simplify operations at the edge
Infrastructure
The latest on the world’s leading enterprise Linux platform
Applications
Inside our solutions to the toughest application challenges
Original shows
Entertaining stories from the makers and leaders in enterprise tech
Products
- Red Hat Enterprise Linux
- Red Hat OpenShift
- Red Hat Ansible Automation Platform
- Cloud services
- See all products
Tools
- Training and certification
- My account
- Customer support
- Developer resources
- Find a partner
- Red Hat Ecosystem Catalog
- Red Hat value calculator
- Documentation
Try, buy, & sell
Communicate
About Red Hat
We’re the world’s leading provider of enterprise open source solutions—including Linux, cloud, container, and Kubernetes. We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.
Select a language
Red Hat legal and privacy links
- About Red Hat
- Jobs
- Events
- Locations
- Contact Red Hat
- Red Hat Blog
- Diversity, equity, and inclusion
- Cool Stuff Store
- Red Hat Summit