Migrating from Knative Build
Tekton Pipelines is the technological successor to Knative Build. Tekton entities are based on Knative Build’s entities but provide additional flexibility and reusability. This page explains how to convert your Knative Build entities to Tekton entities of equivalent functionality.
The table below lists the mapping between the old and new entities:
| Knative Build Entity | Tekton Entity |
|---|---|
Build |
TaskRun |
BuildTemplate |
Task |
ClusterBuildTemplate |
ClusterTask |
Conversion guidelines
Follow the guidelines below when converting your Knative Build entities to Tekton entities:
-
All
stepsmust specify anamevalue. -
BuildTemplateparameters now reside inside theinput.paramsfield of aTask. In a related change, parameter placeholders, such as${FOO}, now follow the format$(input.parameters.FOO). For more information, see Using variable substitution. -
Tasksthat ingest inputs from resources must now explicitly specifyinput.resources.BuildTemplatesdid not explicitly specify input resources and just assumed those resources were always available. -
Input resource data is no longer cloned into the
/workspacedirectory. Instead, Tekton clones the data into a subdirectory of your choice within the/workspacedirectory. You must specify this subdirectory using thenamefield in your input resource definition. For example, if you specify agitresource namedfoo, Tekton clones the data into/workspace/foo. Due to this change, we highly recommend that you setworkingDir: /workspace/fooin the affectedstepswithin yourTask. For more information, see Controlling where resources are mounted. -
TaskRunswhich specify aPipelineResourceas the value of theinput.resourcesfield of the invokedTaskcan do so either by referencing an existingPipelineResourceusing theresourceReffield or by embedding a completePipelineResourcedefinition using theresourceSpecfield.⚠️
PipelineResourcesare deprecated.Consider using replacement features instead. Read more in documentation and TEP-0074.
-
Containers that execute the
Stepsin yourTasksmust now abide by Tekton’s container contract and are now serialized without relying on init containers. Because of this, we highly recommend that for eachStepwithin yourTaskyou specify acommandvalue instead of anentrypointandargspair.
Code examples
Study the following code examples to better understand the conversion of entities described earlier in this document.
Converting a BuildTemplate to a Task
This example BuildTemplate runs go test.
apiVersion: build.knative.dev/v1alpha1
kind: BuildTemplate
metadata:
name: go-test
spec:
parameters:
- name: TARGET
description: The Go target to test
default: ./...
steps:
- image: golang
args: ['go', 'test', '${TARGET}']
Below is an equivalent Task.
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: go-test
spec:
params:
- name: TARGET
description: The Go target to test
default: ./...
# The Task must operate on a source, such as a Git repo.
resources:
inputs:
- name: source
type: git
steps:
- name: go-test # <-- the step must specify a name.
image: golang
workingDir: /workspace/source # <-- set workingdir
command: ['go', 'test', '$(params.TARGET)'] # <-- specify params.TARGET
Converting a Build to a TaskRun
This example Build instantiates and runs the BuildTemplate from the previous example.
apiVersion: build.knative.dev/v1alpha1
kind: Build
metadata:
name: go-test
spec:
source:
git:
url: https://github.com/my-user/my-repo
revision: master
template:
name: go-test
arguments:
- name: TARGET
value: ./path/to/test/...
Below is an equivalent TaskRun.
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
name: example-run
spec:
taskRef:
name: go-test
params:
- name: TARGET
value: ./path/to/test/...
resources:
inputs:
- name: source
resourceSpec:
type: git
params:
- name: url
value: https://github.com/my-user/my-repo
Feedback
Was this page helpful?
Thanks! Tell us how we can further improve.
Sorry about that. Tell us how we can further improve.