

How to use continuous integration with Jenkins on OpenShift
source link: https://developers.redhat.com/articles/2023/02/28/how-use-continuous-integration-jenkins-openshift
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to use continuous integration with Jenkins on OpenShift Skip to main content

In this article series, we will set up a 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:
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 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.
Install Jenkins on OpenShift
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.
Follow these six steps to install Jenkins on OpenShift:
- From OpenShift Web Console, switch to the Developer perspective and navigate to the Topology view. Click on +Add > From Developer Catalog > All services
- Search for Jenkins.
- 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).
- After installation, one Jenkins pod should appear in the project.
- To access the dashboard of Jenkins, click on the route icon.
- For Jenkins dashboard access, you can use the OpenShift console credential, as shown in Figure 3.
Set up Jenkins CI pipeline
Set up Jenkins CI pipeline
The continuous integration stage consists of building and pushing the image into the container registry.
- Make sure to have one git repository in place, including the Dockerfile and application dependencies like the requirements.txt file.
- 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).
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.
11. Once the pipeline is ready, execute it by clicking the Build Nowbutton. You can see a glimpse of the pipeline in Figure 6.
What’s Next?
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.
Recommend
-
33
You write unit tests for your code, but do you run all your tests whenever you add new code and tests? Or at least, just before you push a commit to your repository? As your app grows, the number of unit tests gro...
-
16
Jenkins is an open-source continuous integration and delivery system designed to ensure build and deploy automation. It is well...
-
6
Continuous Integration is the most important part of DevOps that is used to integrate various DevOps stages. Jenkins is the most famous Continuous Integration tool, I know...
-
6
A great way to perform continuous integration with angular CLI and Jenkins advertisements I trying to configure a correct way to perform a continio...
-
14
Article Deploy Helm charts with Jenkins CI/CD in Red Hat OpenShift 4 ...
-
3
Sheldoncooper3991 Posted on Nov 18...
-
6
Tutorial How To Set Up Continuous Integration Pipelines in Jenkins on Ubuntu 20.04 Ubuntu
-
5
Openshift Token Credentials
-
9
How to employ continuous deployment with Ansible on OpenShift Skip to main conte...
-
8
Continuous Integration in AWS Using Jenkins Pipelines: Best Practices and Strategies ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK