permalink |
---|
/guides/jenkins-integration-with-kabanero/ |
Kabanero delivers a modern DevOps toolchain with pre-built Tekton pipelines. The Tekton open source project provides Kubernetes-style resources for declaring CI/CD-style pipelines. While it is advantageous to run both CI and CD with Tekton to leverage the power of Kubernetes, some might want to reuse Jenkins assets or skills.
With Kabanero, you can customize the deployment section of the pipeline to use Jenkins.
In this guide, you will learn how to use Tekton to build an image and how to use Jenkins to deploy an application that uses that image. Tekton pipelines are created manually in this guide. A separate guide will address how to use automated webhooks to create and run Tekton pipelines.
The following diagram depicts the relationship and flow between Tekton and Jenkins:
You need the following prerequisites to complete the guide:
-
Kabanero Foundation (cloned)
-
Kabanero Pipelines (cloned)
-
Appsody (installed)
See each project’s documentation for necessary system requirements.
The purpose of the guide is to show an existing Jenkins user or administrator how to build an image with Tekton and how to deploy an image with Jenkins.
Users should have experience with Jenkins and be familiar with the fundamental concepts of microservices, Docker, Kubernetes, and Tekton.
The script to create a pipeline is included with the Kabanero Pipelines project. This template script contains both build and deployment tasks, but you will remove the deployment task from the file so that Tekton performs only the build task.
Go to the kabanero-pipelines
folder that you recently cloned. Find the pipelines/incubator/build-deploy-pipeline.yaml
file, and delete the following section of the file:
- name: deploy-task
taskRef:
name: CollectionId-deploy-task
runAfter: [build-task]
resources:
inputs:
- name: git-source
resource: git-source
- name: docker-image
resource: docker-image
You removed the deployment task. Save and close the file. Rename the file to test-build-pipeline.yaml
.
In the test-build-pipeline.yaml
file, update the name of the build task to nodejs-express-build-task
. The taskRef name must be one of the tasks that is installed in the OpenShift cluster. Then, update the pipeline name to test-build-pipeline
. After you make these changes, your file looks like following example:
apiVersion: Tekton.dev/v1alpha1
kind: Pipeline
metadata:
name: test-build-pipeline
spec:
resources:
- name: git-source
type: git
- name: docker-image
type: image
tasks:
- name: build-task
taskRef:
name: nodejs-express-build-task
resources:
inputs:
- name: git-source
resource: git-source
outputs:
- name: docker-image
resource: docker-image
Now, run the following command to create the pipeline:
oc apply -f test-build-pipeline.yaml -n Kabanero
In the command, the -n
indicates the Kabanero namespace where the pipeline is created.
Note: You can use a project of your choice to complete this guide. If you don’t have a project yet, run the appsody init nodejs-express
command to get a sample Node.js - Express application.
Go to the Kabanero Foundation project that you cloned and open the scripts/appsody-Tekton-example-manual-run.sh
file. In this file, edit the DOCKER_IMAGE
and APP_REPO
parameters to reflect the code repository and image repository of your choice. For this example, use the Docker repository on OpenShift.
Run the following command to create a PipelineRun binary:
./appsody-Tekton-example-manual-run.sh
Run the following command to see the running PipelineRuns:
oc get pipelinerun
Run the following command to display the PipelineRun execution steps:
oc get pipelinerun -o yaml
If the PipelineRun fails at the validate-collection-is-active
step, remove the appsody/nodejs-express:<ver>
value and add the Kabanero/nodejs-express:<ver>
value in the appsody-config.yaml
file under the Appsody project.
This problem is a known issue for projects that are created by using the appsody-init
command.
Use the Jenkinsfile template from the reference section of this guide, and change the Docker Hub source to your own image repository. Push this Jenkinsfile to your GitHub repository in the root location.
On your local environment where Appsody is installed, go to your project folder and run the following command to generate an app-deploy.yaml
file:
appsody-deploy –-generate-only
Other tools, including Jenkins, can use this file for application deployment. Commit and push this file to the root of your project. Jenkins creates the AppsodyApplication
resource in the OpenShift cluster and uses Appsody to deploy the application by using app-deploy.yaml
file.
Create a Jenkins (Ephemeral) instance from the OpenShift Catalog. Create a project and specify GitHub as the source. Provide your GitHub account and repository details and choose multi-branch pipeline creation. Jenkins automatically detects the Jenkinsfile in your GitHub repository and starts the deployment process.
-
The following file is a sample Jenkinsfile that you can use to set up your initial Jenkinsfile for the guide:
podTemplate(label: 'label', cloud: 'openshift', serviceAccount: 'appsody-sa', containers: [ containerTemplate(name: 'kubectl', image: 'lachlanevenson/k8s-kubectl', ttyEnabled: true, command: 'cat') ]){ node('label') { stage('Deploy') { container('kubectl') { checkout scm sh 'sed -i -e \'s#applicationImage: .*$#applicationImage: docker-registry.default.svc:5000/Kabanero/project1#g\' app-deploy.yaml' sh 'cat app-deploy.yaml' sh 'find . -name app-deploy.yaml -type f|xargs kubectl apply -f' } } } }
-
This guide has been tested on the following product versions: OpenShift 4.2 Platform, Kabanero Foundation 0.3.1, Tekton 0.7, Jenkins ver. 2.176.3