Automated Hooks in Tekton
CI and CD pipelines require automation, automation of tests, builds and deployments.
I’ve written before about Tekton, and using EventListeners to drive pipelines.
More recently, I’ve been looking at ways to simplify the configuration of deploying these pipelines.
Introducing Tekton CI, which makes it easy to define the pipeline configuration in the same repository as the code resides.
This is an early alpha-release, it works, but it’s under heavy development.
The Deployment exposes an HTTP service on 8080 with two endpoints.
Hook endpoints
The container supports two different formats for driving pipelines, both accept
incoming PullRequest
hooks and fetch a pipeline definition from the source
repository.
/pipeline
will drive a simplified script-based PipelineDSL/pipelinerun
will drive pipelines directly from a PipelineRun definition.
Script DSL
The /pipeline
endpoint will look for a file called .tekton_ci.yaml
in the
root of the repository.
It supports a simplified script format, see this example.
When a PullRequest is opened, this will be executed as a PipelineRun with an embedded Pipeline, with embedded Tasks based on the scripts in the definition.
The source is checked out to a shared volume and the scripts are executed in the “root” of the checked out code.
PipelineRun definition
The /pipelinerun
endpoint will look for a file called .tekton/pull_request.yaml
.
# This is a CEL expression
filter: hook.Action == 'opened'
# These are applied to the created PipelineRun, the expression is a CEL
# expression, and the `hook` value is an scm Hook value, for example
# https://github.com/jenkins-x/go-scm/blob/master/scm/webhook.go#L251
paramBindings:
- name: COMMIT_SHA
expression: hook.PullRequest.Sha
# this is a standard Pipeline Run specification.
pipelineRunSpec:
pipelineSpec:
params:
- name: COMMIT_SHA
description: "The commit from the pull_request"
type: string
tasks:
- name: echo-commit
taskSpec:
params:
- name: COMMIT
type: string
steps:
- name: echo
image: ubuntu
script: |
#!/usr/bin/env bash
echo "$(params.COMMIT)"
params:
- name: COMMIT
value: $(params.COMMIT_SHA)
Feel free to build and install the code, and submit issues or feedback.