Migrating from Knative Build

This doc describes a process for users who are familiar with Knative Build andBuildTemplate resources to migrate to Tekton TaskRuns and Tasks, respectively.

Tekton’s resources are heavily influenced by Knative’s Build-related resources,with some additional features that enable them to be chained together inside aPipeline, and provide additional flexibility and reusability.

KnativeTekton
BuildTaskRun
BuildTemplateTask
ClusterBuildTemplateClusterTask

Important differences

  • All steps must have a name.

  • BuildTemplateparametersare moved inside Task’s input.params field, and parameter placeholderstrings (e.g., ${FOO}) must be specified like $(input.parameters.FOO)(see variable substitution).

  • Tasks must specifyinput.resourcesif they need to operate on a resource (e.g., source from a Git repo).BuildTemplates did not specify input resource requirements, and just assumedwhatever source was available.

  • Input resources must specify a name, which is the directory within/workspace where the resource’s source will be placed. So if you specify agit-type resource named foo, the source will be cloned into/workspace/foo – make sure to either set workingDir: /workspace/foo inthe Task’s steps, or at least be aware that source will not be cloned into/workspace as was the case with Knative Builds. See Controlling whereresources aremountedfor more information.

  • TaskRuns which specify a PipelineResource to satisfy a Task’s input.resourcescan do so either by referencing an existing PipelineResource resource in itsresourceRef, or by fully specifying the resource in itsresourceSpec.

  • Because of how steps are serialized without relying on init containers, stepsshould specify a command instead ofentrypointand args. If the image’s entrypoint isn’t defined, Tekton will attemptto determine the image’s entrypoint. This field can be a list of strings,so instead of specifying args: ['foo', 'bar'] and assuming the image’sentrypoint (e.g., /bin/entrypoint) as before, you can specifycommand: ['/bin/entrypoint', 'foo, bar'].

Example

BuildTemplate -> Task

Given this example BuildTemplate which runs go test*:

  1. apiVersion: build.knative.dev/v1alpha1
  2. kind: BuildTemplate
  3. metadata:
  4. name: go-test
  5. spec:
  6. parameters:
  7. - name: TARGET
  8. description: The Go target to test
  9. default: ./...
  10. steps:
  11. - image: golang
  12. args: ['go', 'test', '${TARGET}']

*This is just an example BuildTemplate, for illustration purposes only.

This is the equivalent Task:

  1. apiVersion: tekton.dev/v1beta1
  2. kind: Task
  3. metadata:
  4. name: go-test
  5. spec:
  6. params:
  7. - name: TARGET
  8. description: The Go target to test
  9. default: ./...
  10. # The Task must operate on some source, e.g., in a Git repo.
  11. resources:
  12. inputs:
  13. - name: source
  14. type: git
  15. steps:
  16. - name: go-test # <-- the step must specify a name.
  17. image: golang
  18. workingDir: /workspace/source # <-- set workingdir
  19. command: ['go', 'test', '$(params.TARGET)'] # <-- specify params.TARGET

Build -> TaskRun

Given this example Build which instantiates and runs the aboveBuildTemplate:

  1. apiVersion: build.knative.dev/v1alpha1
  2. kind: Build
  3. metadata:
  4. name: go-test
  5. spec:
  6. source:
  7. git:
  8. url: https://github.com/my-user/my-repo
  9. revision: master
  10. template:
  11. name: go-test
  12. arguments:
  13. - name: TARGET
  14. value: ./path/to/test/...

This is the equivalent TaskRun:

  1. apiVersion: tekton.dev/v1beta1
  2. kind: TaskRun
  3. metadata:
  4. name: example-run
  5. spec:
  6. taskRef:
  7. name: go-test
  8. params:
  9. - name: TARGET
  10. value: ./path/to/test/...
  11. resources:
  12. inputs:
  13. - name: source
  14. resourceSpec:
  15. type: git
  16. params:
  17. - name: url
  18. value: https://github.com/my-user/my-repo