Tekton CLI

Puneet Punamiya
3 min readFeb 17, 2021

--

Before we begin let’s understand a little about Tekton

Tekton is a cloud native continuous integration and delivery (CI/CD) solution. It allows developers to build, test, and deploy across cloud providers and on-premise systems. It consists of Tekton Pipelines, which provides the building blocks, and of supporting components, such as Tekton CLI and Tekton Catalog, that make Tekton a complete ecosystem.

Tekton installs and runs as an extension on a Kubernetes cluster and comprises a set of Kubernetes Custom Resources that define the building blocks you can create and reuse for your pipelines. Once installed, Tekton Pipelines becomes available via the Kubernetes CLI (kubectl) and via API calls, just like pods and other resources.

Let’s jump to Tekton CLI

Tekton provides a CLI, tkn, for easier interaction with Tekton components. It is available as a binary executable on major platforms; you may also build it from the source, or set it up as a kubectl plugin

Installation

One can find the complete guide for installation here

Once installed, run tkn to see the list of all available commands

─ tkn
CLI for tekton pipelines
Usage:
tkn [flags]
tkn [command]
Available Commands:
clustertask Manage ClusterTasks
clustertriggerbinding Manage ClusterTriggerBindings
condition Manage Conditions
eventlistener Manage EventListeners
hub Interact with tekton hub
pipeline Manage pipelines
pipelinerun Manage PipelineRuns
resource Manage pipeline resources
task Manage Tasks
taskrun Manage TaskRuns
triggerbinding Manage TriggerBindings
triggertemplate Manage TriggerTemplates
Other Commands:
completion Prints shell completion scripts
version Prints version information
Flags:
-h, --help help for tkn
Use "tkn [command] --help" for more information about a command.

Source code for Tekton CLI can be found here

Now let’s build a simple Hello-Tekton Pipeline using tkn

Fork/Clone the manifest for pipeline and task from here

Now follow the steps to build and deploy the pipeline

Step 1: Install the tasks

kubectl apply -f hello.yaml   kubectl apply -f good-bye.yaml

You can list the task to see the tasks installed

╰─ tkn task list        
NAME DESCRIPTION AGE
goodbye Bye Tekton 4 seconds ago
hello Hello from Tekton 10 seconds ago

Step 2: Install the pipeline

kubectl apply -f hello-pipeline.yaml

You can list the pipeline to see the pipelines installed

╰─ tkn pipeline list                                     
NAME AGE LAST RUN STARTED DURATION STATUS
hello-bye 12 seconds ago --- --- --- ---

Step 3: Now let’s start the pipeline

╰─ tkn pipeline start hello-bye
PipelineRun started: hello-bye-run-n22n8
In order to track the PipelineRun progress run:
tkn pipelinerun logs hello-bye-run-n22n8 -f -n default

This will start the task and create taskruns and we can see the desired output in the pipelinerun logs

Let’s list the taskruns first with it’s corresponding logs

╰─ tkn taskruns list                               
NAME STARTED DURATION STATUS
hello-bye-run-n22n8-goodbye-t6l9q 2 minutes ago 6 seconds Succeeded
hello-bye-run-n22n8-hello-xjfd2 2 minutes ago 6 seconds Succeeded

Logs of Hello-Tekton taskrun

╰─ tkn taskruns logs hello-bye-run-n22n8-hello-xjfd2               
[hello] Hello Tekton

Logs of GoodBye-Tekton taskrun

╰─ tkn taskruns logs hello-bye-run-n22n8-goodbye-t6l9q
[goodbye] + set -e
[goodbye] + echo Goodbye Tekton!
[goodbye] Goodbye Tekton!

Finally let’s list the Pipelinerun and it logs

╰─ tkn pipelinerun list                                  
NAME STARTED DURATION STATUS
hello-bye-run-n22n8 6 minutes ago 12 seconds Succeeded

Logs of Pipelinerun

╰─ tkn pr logs hello-bye-run-n22n8  
[hello : hello] Hello Tekton
[goodbye : goodbye] + set -e
[goodbye : goodbye] + echo Goodbye Tekton!
[goodbye : goodbye] Goodbye Tekton!

--

--

No responses yet