tkn pac generate
Generate a simple PipelineRun template to get started with Pipelines-as-Code.
Synopsis
tkn pac generate [flags]
tkn pac gen [flags]
Description
The generate command creates a basic PipelineRun template in the .tekton/ directory. It:
Detects Git information from current directory
Performs language detection (Python, Go, Node.js, etc.)
Adds relevant tasks based on detected language
Creates .tekton/ directory if it doesn’t exist
Generates a customizable template
Usage Examples
Interactive Mode
Pull Request Event
Push Event
Custom File Name
Specific Language
Overwrite Existing
Custom Branch
# Generate with interactive prompts
tkn pac generate
Interactive Prompts
When run without flags:
1. Event Type Selection
? Enter the Git event type for triggering the pipeline:
› Pull Request
Push to a Branch or a Tag
2. Target Branch
For pull requests :
Enter the target Git branch for the Pull Request (default: main):
For push events :
Enter a target Git branch or tag for the push (default: main):
3. File Overwrite Confirmation
If the file already exists:
A file named .tekton/pull-request.yaml already exists. Would you like to override it? (y/N)
Flags
Event type: pull_request or push
Target branch for the PipelineRun (e.g., main, develop, feature/*)
Output file location (default: .tekton/<event>.yaml)
Overwrite existing file without prompting
Generate template for specific programming language
Language Detection
The generator detects languages by looking for specific files:
Language Detection Files Added Tasks Python setup.py, pyproject.toml, requirements.txtpylint Go go.mod, go.sumgolangci-lint Node.js package.jsonnpm Java pom.xml, build.gradlemaven Ruby Gemfilerubocop
Language detection adds relevant linting and testing tasks automatically.
Generated File Structure
Default File Naming
Generated files are named based on event type:
Pull Request : .tekton/pull-request.yaml
Push : .tekton/push.yaml
Multiple events : .tekton/pipelinerun.yaml
Directory Creation
If .tekton/ doesn’t exist:
ℹ️ Directory .tekton has been created.
Output Example
$ tkn pac generate
? Enter the Git event type for triggering the pipeline: Pull Request
? Enter the target GIT branch for the Pull Request ( default: main ): main
ℹ️ Directory .tekton has been created.
✓ A basic template has been created in .tekton/pull-request.yaml, feel free to customize it.
ℹ️ You can test your pipeline by pushing the generated template to your git repository
Generated Template Examples
Basic Template
.tekton/pull-request.yaml
apiVersion : tekton.dev/v1
kind : PipelineRun
metadata :
name : my-app-pull-request
annotations :
pipelinesascode.tekton.dev/on-event : "[pull_request]"
pipelinesascode.tekton.dev/on-target-branch : "[main]"
spec :
pipelineSpec :
tasks :
- name : fetch-repository
taskRef :
name : git-clone
resolver : hub
workspaces :
- name : output
workspace : source
params :
- name : url
value : "{{ repo_url }}"
- name : revision
value : "{{ revision }}"
workspaces :
- name : source
emptyDir : {}
Python Project Template
When setup.py is detected:
.tekton/pull-request.yaml
apiVersion : tekton.dev/v1
kind : PipelineRun
metadata :
name : python-app-pull-request
annotations :
pipelinesascode.tekton.dev/on-event : "[pull_request]"
pipelinesascode.tekton.dev/on-target-branch : "[main]"
spec :
pipelineSpec :
tasks :
- name : fetch-repository
taskRef :
name : git-clone
resolver : hub
workspaces :
- name : output
workspace : source
params :
- name : url
value : "{{ repo_url }}"
- name : revision
value : "{{ revision }}"
- name : pylint
runAfter : [ fetch-repository ]
taskRef :
name : pylint
resolver : hub
workspaces :
- name : source
workspace : source
params :
- name : args
value : [ "--disable=C0114" ]
workspaces :
- name : source
emptyDir : {}
Go Project Template
When go.mod is detected:
.tekton/pull-request.yaml
apiVersion : tekton.dev/v1
kind : PipelineRun
metadata :
name : go-app-pull-request
annotations :
pipelinesascode.tekton.dev/on-event : "[pull_request]"
pipelinesascode.tekton.dev/on-target-branch : "[main]"
spec :
pipelineSpec :
tasks :
- name : fetch-repository
taskRef :
name : git-clone
resolver : hub
workspaces :
- name : output
workspace : source
params :
- name : url
value : "{{ repo_url }}"
- name : revision
value : "{{ revision }}"
- name : golangci-lint
runAfter : [ fetch-repository ]
taskRef :
name : golangci-lint
resolver : hub
workspaces :
- name : source
workspace : source
params :
- name : package
value : "./..."
workspaces :
- name : source
emptyDir : {}
Template Variables
Generated templates use these variables (substituted by PAC at runtime):
Variable Description Example {{ repo_url }}Repository URL https://github.com/org/repo{{ revision }}Git commit SHA abc123...{{ target_branch }}Target branch name main{{ source_branch }}Source branch name feature/new{{ event_type }}Event type pull_request{{ sender }}User who triggered username
See Template Variables for complete list.
Customization After Generation
The generated template is a starting point. Common customizations:
Add More Tasks
tasks :
- name : fetch-repository
# ... existing task ...
- name : run-tests
runAfter : [ fetch-repository ]
taskRef :
name : golang-test
resolver : hub
workspaces :
- name : source
workspace : source
- name : build-image
runAfter : [ run-tests ]
taskRef :
name : buildah
resolver : hub
# ... params ...
Add Workspaces
workspaces :
- name : source
volumeClaimTemplate :
spec :
accessModes :
- ReadWriteOnce
resources :
requests :
storage : 1Gi
- name : cache
persistentVolumeClaim :
claimName : build-cache
Add Parameters
spec :
params :
- name : image-name
value : "quay.io/myorg/myapp"
- name : dockerfile
value : "./Dockerfile"
pipelineSpec :
params :
- name : image-name
type : string
- name : dockerfile
type : string
# ... tasks ...
Target Multiple Branches
metadata :
annotations :
pipelinesascode.tekton.dev/on-target-branch : "[main, develop, release/*]"
Common Workflows
Generate and Test Locally
# Generate template
tkn pac generate
# Test locally before pushing
tkn pac resolve -f .tekton/pull-request.yaml | kubectl apply -f -
Generate Multiple Event Types
# Pull request pipeline
tkn pac generate --event-type pull_request --branch main
# Push pipeline
tkn pac generate --event-type push --branch main --file-name .tekton/push.yaml
# Tag pipeline
tkn pac generate --event-type push --branch "refs/tags/*" --file-name .tekton/tag.yaml
Generate per Environment
# Development
tkn pac generate --branch develop --file-name .tekton/dev.yaml
# Staging
tkn pac generate --branch staging --file-name .tekton/staging.yaml
# Production
tkn pac generate --branch main --file-name .tekton/prod.yaml
Troubleshooting
File Already Exists
A file named .tekton/pull-request.yaml already exists.
Solution : Use --overwrite or choose different filename:
tkn pac generate --overwrite
# or
tkn pac generate --file-name .tekton/pr-v2.yaml
Not in Git Repository
ℹ️ Could not detect Git information
Solution : This is not an error. The template will be created without Git-specific defaults.
Permission Denied
Error: cannot write template to .tekton/pull-request.yaml: permission denied
Solution : Check directory permissions:
See Also