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
occommand line tool on the external Jenkins server and useocmechanism 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_HOSTand set the Default Value as your OpenShift host URL. - Boolean parameter named
SKIP_TLSchecked by default. - Password parameter named
AUTH_TOKENset to your token value. You can login to the same OpenShift server usingoc loginon your workstation and runoc whoami -tto get the token value to use here.
- String parameter named
- Scroll down to the end and add the pipeline script in the
Pipelinesection. 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
buildInDevelopmentstage, it starts a build by invoking the build configuration namedmyappin the project nameddevelopmentusing theopenshiftBuildstep. - In the
deployInDevelopmentstage, it deploys using the deployment configuration namedmyappusing theopenshiftDeploystep. Then it scales up the application to 2 replicas using theopenshiftScalestep.
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.
저자 소개
채널별 검색
오토메이션
기술, 팀, 인프라를 위한 IT 자동화 최신 동향
인공지능
고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트
오픈 하이브리드 클라우드
하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요
보안
환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보
엣지 컴퓨팅
엣지에서의 운영을 단순화하는 플랫폼 업데이트
인프라
세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보
애플리케이션
복잡한 애플리케이션에 대한 솔루션 더 보기
가상화
온프레미스와 클라우드 환경에서 워크로드를 유연하게 운영하기 위한 엔터프라이즈 가상화의 미래