|
| 1 | +:_content-type: CONCEPT |
| 2 | +// Module included in the following assembly: |
| 3 | +// |
| 4 | +// jenkins-tekton/migrating-from-jenkins-to-tekton.adoc |
| 5 | + |
| 6 | +[id="jt-examples-of-common-use-cases_{context}"] |
| 7 | += Examples of common use cases |
| 8 | + |
| 9 | +Both Jenkins and Tekton offer capabilities for common CI/CD use cases, such as: |
| 10 | + |
| 11 | +* Compiling, building, and deploying images using maven |
| 12 | +* Extending the core capabilities by using plugins |
| 13 | +* Reusing shareable libraries and custom scripts |
| 14 | + |
| 15 | +== Running a maven pipeline in Jenkins and Tekton |
| 16 | + |
| 17 | +You can use maven in both Jenkins and Tekton workflows for compiling, building, and deploying images. To map your existing Jenkins workflow to Tekton, consider the following examples: |
| 18 | + |
| 19 | +.Example: Compile and build an image and deploy it to OpenShift using maven in Jenkins |
| 20 | +[source,groovy] |
| 21 | +---- |
| 22 | +#!/usr/bin/groovy |
| 23 | +node('maven') { |
| 24 | + stage 'Checkout' |
| 25 | + checkout scm |
| 26 | + |
| 27 | + stage 'Build' |
| 28 | + sh 'cd helloworld && mvn clean' |
| 29 | + sh 'cd helloworld && mvn compile' |
| 30 | + |
| 31 | + stage 'Run Unit Tests' |
| 32 | + sh 'cd helloworld && mvn test' |
| 33 | + |
| 34 | + stage 'Package' |
| 35 | + sh 'cd helloworld && mvn package' |
| 36 | + |
| 37 | + stage 'Archive artifact' |
| 38 | + sh 'mkdir -p artifacts/deployments && cp helloworld/target/*.war artifacts/deployments' |
| 39 | + archive 'helloworld/target/*.war' |
| 40 | + |
| 41 | + stage 'Create Image' |
| 42 | + sh 'oc login https://kubernetes.default -u admin -p admin --insecure-skip-tls-verify=true' |
| 43 | + sh 'oc new-project helloworldproject' |
| 44 | + sh 'oc project helloworldproject' |
| 45 | + sh 'oc process -f helloworld/jboss-eap70-binary-build.json | oc create -f -' |
| 46 | + sh 'oc start-build eap-helloworld-app --from-dir=artifacts/' |
| 47 | + |
| 48 | + stage 'Deploy' |
| 49 | + sh 'oc new-app helloworld/jboss-eap70-deploy.json' } |
| 50 | +
|
| 51 | +---- |
| 52 | + |
| 53 | +.Example: Compile and build an image and deploy it to OpenShift using maven in Tekton. |
| 54 | +[source,yaml] |
| 55 | +---- |
| 56 | +apiVersion: tekton.dev/v1beta1 |
| 57 | +kind: Pipeline |
| 58 | +metadata: |
| 59 | + name: maven-pipeline |
| 60 | +spec: |
| 61 | + workspaces: |
| 62 | + - name: shared-workspace |
| 63 | + - name: maven-settings |
| 64 | + - name: kubeconfig-dir |
| 65 | + optional: true |
| 66 | + params: |
| 67 | + - name: repo-url |
| 68 | + - name: revision |
| 69 | + - name: context-path |
| 70 | + tasks: |
| 71 | + - name: fetch-repo |
| 72 | + taskRef: |
| 73 | + name: git-clone |
| 74 | + workspaces: |
| 75 | + - name: output |
| 76 | + workspace: shared-workspace |
| 77 | + params: |
| 78 | + - name: url |
| 79 | + value: "$(params.repo-url)" |
| 80 | + - name: subdirectory |
| 81 | + value: "" |
| 82 | + - name: deleteExisting |
| 83 | + value: "true" |
| 84 | + - name: revision |
| 85 | + value: $(params.revision) |
| 86 | + - name: mvn-build |
| 87 | + taskRef: |
| 88 | + name: maven |
| 89 | + runAfter: |
| 90 | + - fetch-repo |
| 91 | + workspaces: |
| 92 | + - name: source |
| 93 | + workspace: shared-workspace |
| 94 | + - name: maven-settings |
| 95 | + workspace: maven-settings |
| 96 | + params: |
| 97 | + - name: CONTEXT_DIR |
| 98 | + value: "$(params.context-path)" |
| 99 | + - name: GOALS |
| 100 | + value: ["-DskipTests", "clean", "compile"] |
| 101 | + - name: mvn-tests |
| 102 | + taskRef: |
| 103 | + name: maven |
| 104 | + runAfter: |
| 105 | + - mvn-build |
| 106 | + workspaces: |
| 107 | + - name: source |
| 108 | + workspace: shared-workspace |
| 109 | + - name: maven-settings |
| 110 | + workspace: maven-settings |
| 111 | + params: |
| 112 | + - name: CONTEXT_DIR |
| 113 | + value: "$(params.context-path)" |
| 114 | + - name: GOALS |
| 115 | + value: ["test"] |
| 116 | + - name: mvn-package |
| 117 | + taskRef: |
| 118 | + name: maven |
| 119 | + runAfter: |
| 120 | + - mvn-tests |
| 121 | + workspaces: |
| 122 | + - name: source |
| 123 | + workspace: shared-workspace |
| 124 | + - name: maven-settings |
| 125 | + workspace: maven-settings |
| 126 | + params: |
| 127 | + - name: CONTEXT_DIR |
| 128 | + value: "$(params.context-path)" |
| 129 | + - name: GOALS |
| 130 | + value: ["package"] |
| 131 | + - name: create-image-and-deploy |
| 132 | + taskRef: |
| 133 | + name: openshift-client |
| 134 | + runAfter: |
| 135 | + - mvn-package |
| 136 | + workspaces: |
| 137 | + - name: manifest-dir |
| 138 | + workspace: shared-workspace |
| 139 | + - name: kubeconfig-dir |
| 140 | + workspace: kubeconfig-dir |
| 141 | + params: |
| 142 | + - name: SCRIPT |
| 143 | + value: | |
| 144 | + cd "$(params.context-path)" |
| 145 | + mkdir -p ./artifacts/deployments && cp ./target/*.war ./artifacts/deployments |
| 146 | + oc new-project helloworldproject |
| 147 | + oc project helloworldproject |
| 148 | + oc process -f jboss-eap70-binary-build.json | oc create -f - |
| 149 | + oc start-build eap-helloworld-app --from-dir=artifacts/ |
| 150 | + oc new-app jboss-eap70-deploy.json |
| 151 | +
|
| 152 | +---- |
| 153 | + |
| 154 | +== Extending the core capabilities of Jenkins and Tekton by using plugins |
| 155 | +Jenkins has the advantage of a large ecosystem of numerous plugins developed over the years by its extensive user base. You can search and browse the plugins in the link:https://plugins.jenkins.io/[Jenkins Plugin Index]. |
| 156 | + |
| 157 | +Tekton also has many tasks developed and contributed by the community and enterprise users. A publicly available catalog of reusable Tekton tasks are available in the link:https://hub.tekton.dev/[Tekton Hub]. |
| 158 | + |
| 159 | +In addition, Tekton incorporates many of the plugins of the Jenkins ecosystem within its core capabilities. For example, authorization is a critical function in both Jenkins and Tekton. While Jenkins ensures authorization using the link:https://plugins.jenkins.io/role-strategy/[Role-based Authorization Strategy] plugin, Tekton uses OpenShift's built-in Role-based Access Control system. |
| 160 | + |
| 161 | +== Sharing reusable code in Jenkins and Tekton |
| 162 | +Jenkins link:https://www.jenkins.io/doc/book/pipeline/shared-libraries/[shared libraries] provide reusable code for parts of Jenkins pipelines. The libraries are shared between link:https://www.jenkins.io/doc/book/pipeline/jenkinsfile/[Jenkinsfiles] to create highly modular pipelines without code repetition. |
| 163 | + |
| 164 | +Although there is no direct equivalent of Jenkins shared libraries in Tekton, you can achieve similar workflows by using tasks from the link:https://hub.tekton.dev/[Tekton Hub], in combination with custom tasks and scripts. |
0 commit comments