Overview
Pipelines-as-Code allows you to define your Tekton pipelines directly in your Git repository. Pipeline definitions are stored in the.tekton/ directory and automatically executed when Git events occur.
Pipelines-as-Code stays as close to standard Tekton templates as possible. Write your templates as
.yaml files, and PAC will run them.Directory Structure
The.tekton directory must be at the top level of your repository:
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: pr-build
annotations:
pipelinesascode.tekton.dev/on-event: "[pull_request]"
pipelinesascode.tekton.dev/on-target-branch: "[main]"
spec:
params:
- name: repo_url
value: "{{ repo_url }}"
- name: revision
value: "{{ revision }}"
pipelineSpec:
params:
- name: repo_url
- name: revision
tasks:
- name: fetch-repository
taskRef:
name: git-clone
resolver: hub
workspaces:
- name: output
workspace: source
params:
- name: url
value: "$(params.repo_url)"
- name: revision
value: "$(params.revision)"
- name: run-tests
runAfter: [fetch-repository]
taskRef:
name: golang-test
resolver: hub
workspaces:
- name: source
workspace: source
workspaces:
- name: source
emptyDir: {}
Dynamic Variables
Pipelines-as-Code provides template variables that are replaced at runtime with values from the Git event.Essential Variables
The full URL of the repositoryExample:
https://github.com/openshift-pipelines/pipelines-as-codeThe commit SHA being testedExample:
1234567890abcdefThe branch the event targets (for PRs: base branch; for push: the branch pushed to)Example:
mainThe branch where the event originates (for PRs: head branch; for push: same as target_branch)Example:
feature/my-featureAll Available Variables
| Variable | Description | Example |
|---|---|---|
body | Full webhook payload | {{ body.pull_request.user.email }} |
event | Normalized event type | pull_request, push, or incoming |
event_type | Provider-specific event type | pull_request (GitHub), Merge Request (GitLab) |
git_auth_secret | Auto-generated secret for private repos | pac-gitauth-xkxkx |
headers | Request headers | {{ headers['x-github-event'] }} |
pull_request_number | PR/MR number | 42 |
repo_name | Repository name | pipelines-as-code |
repo_owner | Repository owner | openshift-pipelines |
repo_url | Full repository URL | https://github.com/openshift-pipelines/pipelines-as-code |
revision | Commit SHA | 1234567890abcdef |
sender | Username of the event sender | johndoe |
source_branch | Source branch name | feature-branch |
git_tag | Git tag (only for tag push events) | v1.0.0 |
source_url | Source repository URL | https://github.com/fork/repo |
target_branch | Target branch name | main |
target_namespace | Namespace where Repository CR matched | my-namespace |
trigger_comment | Comment that triggered the run (GitOps commands) | /test my-pipeline |
pull_request_labels | PR labels (newline-separated) | bug\nenhancement |
Using Variables
Variables use double-brace syntax:{{ variable_name }}
Advanced Variable Usage
Accessing Webhook Body
You can access any field from the webhook payload:Object Values in YAML
When passing objects or multiline values, use block format:CEL Expressions
For complex expressions, use thecel: prefix:
body- Full webhook payloadheaders- HTTP headersfiles- Changed files (files.all,files.added,files.deleted,files.modified,files.renamed)pac- Standard PAC parameters (pac.revision,pac.target_branch, etc.)
PipelineRun Structure
Required Components
annotations:
pipelinesascode.tekton.dev/on-event: "[pull_request]"
pipelinesascode.tekton.dev/on-target-branch: "[main]"
Complete Examples
Python CI Pipeline
.tekton/python-ci.yaml
Container Build Pipeline
.tekton/build-push.yaml
Conditional Execution
.tekton/docs-validation.yaml
Using GitHub App Token
Access the GitHub API using the temporary installation token:- GitHub App tokens are available for 8 hours
- Tokens are scoped to the repository by default (configurable via settings)
Best Practices
# ✅ Good
params:
- name: url
value: "{{ repo_url }}"
# ❌ Bad
params:
- name: url
value: "https://github.com/myorg/myrepo"
tasks:
- name: fetch-repository
taskRef:
name: git-clone
resolver: hub
params:
- name: url
value: "{{ repo_url }}"
- name: revision
value: "{{ revision }}"
Next Steps
Event Matching
Learn how to match PipelineRuns to specific events, branches, and file changes
Pipeline Resolution
Understand how PAC resolves tasks and pipelines from remote sources
Running Pipelines
Configure execution, permissions, and monitoring
Repository CRD
Configure the Repository Custom Resource