Create custom tasks.
Use tasks and cluster tasks in pipelines.
Create, manage, and execute pipelines.
Outcomes
Create Tekton tasks.
Create Tekton pipelines.
Use tasks and cluster tasks in custom Tekton pipelines.
Start and troubleshoot Tekton pipelines.
As the student user on the workstation machine, use the lab command to prepare
your environment for this exercise, and to ensure that all required resources are available.
[student@workstation ~]$ lab start pipelines-review
Instructions
In this lab, you create a pipeline that builds and deploys the vertx-site application.
The lab script generates an OpenShift secret that you use in one of the pipeline tasks.
You can test your pipeline by using the PipelineRun object in the /home/student/DO288/labs/pipelines-review/run.yaml file.
To test the pipeline multiple times, first remove the pipeline run by using the oc delete -f run.yaml command, and then recreate the object.
Log in to Red Hat OpenShift.
Log in to OpenShift as the developer user.
[student@workstation ~]$ oc login -u developer -p developer \
https://api.ocp4.example.com:6443
Login successful.
...output omitted...Ensure that you use the pipelines-review project.
[student@workstation ~]$ oc project pipelines-review
Already on project "pipelines-review" on server "https://api.ocp4.example.com:6443".The application includes a Containerfile that uses registry.ocp4.example.com:8443/ubi8/openjdk-11 as the base image.
To prevent permission problems in the pipeline execution, make this image public in the internal Quay registry.
Open the Quay website at https://registry.ocp4.example.com:8443 and log in with the developer user and the developer password.
Search for the ubi8/openjdk-11 repository.
In the section of the ubi8/openjdk-11 settings, make the repository public.
In the pipeline YAML file, define a task to clone the application. Use the following parameters:
Use the git-clone cluster task.
Pass the Git URL property from the pipeline inputs to the task.
Pass the Git revision property from the pipeline inputs to the task.
Configure the task to use the shared workspace.
Navigate to the /home/student/DO288/labs/pipelines-review/ directory.
[student@workstation ~]$cd /home/student/DO288/labs/pipelines-review...no output expected...
Discover the parameter names for the git-clone cluster task.
[student@workstation pipelines-review]$tkn ct describe git-clone...output omitted... Params NAME TYPE DESCRIPTION DEFAULT VALUE ∙urlstring Repository URL to c... --- ∙revisionstring Revision to checkou... ∙ refspec string Refspec to fetch be... ...output omitted...
Edit the pipeline.yaml file and configure the clone-repository task:
...file omitted... tasks: - name: clone-repository taskRef:name: git-clone kind: ClusterTaskparams:- name: url value: $(params.GIT_REPO) - name: revision value: $(params.GIT_REVISION)- name: deleteExisting value: 'true' - name: sslVerify value: 'false' workspaces:- name: output workspace: shared...file omitted...
Define the maven-task task in the task.yaml file.
Use the following parameters:
Use the registry.ocp4.example.com:8443/ubi8/openjdk-11:1.16-3 container image.
Define the following workspaces:
The source workspace contains the git repository.
The maven_config workspace contains the settings.xml file.
Define the app_path parameter that configures the location of the application in the workspace.
Define a working directory that combines the source workspace path with the app_path parameter.
Use the mvn clean package -s /path/to/settings.xml command to build the application.
The pipeline run mounts the settings.xml file from a secret when you start the pipeline.
Then, create the task in Red Hat OpenShift.
Finally, add the task reference to the pipeline.yaml file.
In the task.yaml file, configure the two workspaces and the parameter.
Then, in the steps section, complete the build step.
apiVersion: tekton.dev/v1beta1 kind: Task metadata: name: maven-task spec: workspaces:- name: source - name: maven_configparams:- name: app_path description: Path to the application source code in the directory type: stringsteps: - name: buildimage: registry.ocp4.example.com:8443/ubi8/openjdk-11:1.16-3 workingDir: $(workspaces.source.path)/$(params.app_path) script: | mvn clean package -s $(workspaces.maven_config.path)/settings.xmlsecurityContext: runAsNonRoot: true runAsUser: 65532
Create the maven-task task.
[student@workstation pipelines-review]$ oc create -f task.yaml
task.tekton.dev/maven-task createdIn the pipeline.yaml file, configure the build task:
...file omitted... tasks: ...file omitted... - name: build taskRef:name: maven-task kind: Taskparams:- name: app_path value: $(params.MVN_APP_PATH)runAfter: - clone-repositoryworkspaces:- workspace: shared name: source - workspace: maven_config name: maven_config...file omitted...
In the pipeline, configure the oc-deploy task with the following parameters:
Use the openshift-client cluster task.
Configure the task workspace. The task requires access to the built artifacts from the previous task.
Configure the task to execute the following commands:
cd "$(workspaces.manifest-dir.path)/$(params.MVN_APP_PATH)" || exit 1
oc new-build --name=$(params.DEPLOY_APP_NAME) \
-l app=$(params.DEPLOY_APP_NAME) --binary=true \
--image-stream=openshift/java:8 || echo "BC already exists"
oc start-build $(params.DEPLOY_APP_NAME) --wait=true \
--from-file=$(params.DEPLOY_ARTIFACT_NAME)
oc new-app $(params.DEPLOY_APP_NAME):latest \
--name $(params.DEPLOY_APP_NAME) || echo "application exists"
oc expose svc $(params.DEPLOY_APP_NAME) || echo "route exists"Discover the parameter name for the openshift-client cluster task.
[student@workstation pipelines-review]$tkn ct describe openshift-client...output omitted... Params NAME TYPE DESCRIPTION DEFAULT VALUE ∙SCRIPTstring The OpenShift CLI a... oc help ∙ VERSION string The OpenShift Versi... latest ...output omitted...
Configure the pipeline YAML file.
...file omitted... tasks: ...file omitted... - name: oc-deployrunAfter: - "build"taskRef:name: openshift-client kind: ClusterTaskworkspaces:- name: manifest-dir workspace: sharedparams:- name: SCRIPT value: | cd "$(workspaces.manifest-dir.path)/$(params.MVN_APP_PATH)" || exit 1 oc new-build --name=$(params.DEPLOY_APP_NAME) \ -l app=$(params.DEPLOY_APP_NAME) --binary=true \ --image-stream=openshift/java:8 || echo "BC already exists" oc start-build $(params.DEPLOY_APP_NAME) --wait=true \ --from-file=$(params.DEPLOY_ARTIFACT_NAME) oc new-app $(params.DEPLOY_APP_NAME):latest \ --name $(params.DEPLOY_APP_NAME) || echo "application exists" oc expose svc $(params.DEPLOY_APP_NAME) || echo "route exists"...file omitted...
In the pipeline, configure the skopeo-copy task with the following parameters:
Use the skopeo-copy-internal cluster task.
Configure the source URL to use the docker://default-route-openshift-image-registry.apps.ocp4.example.com/pipelines-review/ format.APP_NAME
Configure the destination URL to use the docker://registry.ocp4.example.com:8443/developer/ format.APP_NAME
Configure the skopeo image to be registry.ocp4.example.com:8443/ubi9/skopeo:9.2.
In both URLs, use the application name pipeline parameter.
Discover the parameter name for the openshift-client cluster task.
[student@workstation pipelines-review]$tkn ct describe skopeo-copy-internal...output omitted... Params NAME TYPE DESCRIPTION DEFAULT VALUE ∙srcImageURLstring URL of the image to... ∙destImageURLstring URL of the image wh... ∙ srcTLSverify string Verify the TLS on t... false ...output omitted... ∙imagestring The image to use ... ...output omitted...
Configure the pipeline YAML file.
...file omitted... - name: skopeo-copyrunAfter: - "oc-deploy"taskRef:name: skopeo-copy-internal kind: ClusterTaskparams:- name: srcImageURL value: docker://default-route-openshift-image-registry.apps.ocp4.example.com/pipelines-review/$(params.DEPLOY_APP_NAME) - name: destImageURL value: docker://registry.ocp4.example.com:8443/developer/$(params.DEPLOY_APP_NAME) - name: image value: registry.ocp4.example.com:8443/ubi9/skopeo:9.2
Create and execute the pipeline.
Create the pipeline.
[student@workstation pipelines-review]$ oc create -f pipeline.yaml
pipeline.tekton.dev/maven-java-pipeline createdExecute the pipeline.
[student@workstation pipelines-review]$ oc create -f run.yaml
pipelinerun.tekton.dev/testrun createdWait until the pipeline finishes.
[student@workstation pipelines-review]$ tkn pipeline \
logs -f -a maven-java-pipeline
2023/08/30 11:49:42 Entrypoint initialization
2023/08/30 11:49:43 Decoded script /tekton/scripts/script-0-ttpl8
+ '[' false = true ']'
...output omitted...Verify that the pipeline succeeded.
[student@workstation pipelines-review]$ tkn pipeline list
NAME AGE LAST RUN STARTED DURATION STATUS
maven-java-pipeline 1 hour ago testrun 1 minute ago 1m18s SucceededIn a web browser, open the vertx-site-pipelines-review.apps.ocp4.example.com URL to verify that the application responds.
Alternatively, test the application by using a curl request.
[student@workstation pipelines-review]$ curl -s \
vertx-site-pipelines-review.apps.ocp4.example.com; echo
<html><body><h1>Welcome to your Vert.x v1.0 application!</h1></body></html>