Create TriggerTemplate
For a comprehensive understanding of TriggerTemplates, including their architecture, advantages, and underlying principles, see the In-Depth Understanding of TriggerTemplate document.
TOC
OverviewSupported Resource TypesBasic StructureParameter Configuration1. Parameter Definition2. Parameter Usage3. Parameter TypesJSON Object HandlingBest PracticesFrequently Asked QuestionsUsage Examples1. Basic CI/CD Pipeline2. Multi-Environment DeploymentReference LinksOverview
A TriggerTemplate is a resource used to define a blueprint for resources that can be instantiated and executed, such as TaskRun or PipelineRun, when the EventListener detects an event. It offers parameterization capabilities, allowing you to use these parameters anywhere within the resource template.
Supported Resource Types
TriggerTemplate currently supports the following Tekton Pipelines resources:
Recommendation: use
tekton.dev/v1for the following resources;tekton.dev/v1beta1is still accepted but is deprecated and will be removed in a future release.
Basic Structure
Here is a typical example of a TriggerTemplate definition:
Parameter Configuration
1. Parameter Definition
Define parameters in spec.params:
2. Parameter Usage
Use parameters within the resource template:
- Basic syntax:
$(tt.params.parameter_name) - Example:
$(tt.params.gitrevision)
3. Parameter Types
Parameters in a TriggerTemplate only support string type values. Each parameter includes the following fields:
name: Parameter name (required)description: Parameter description (optional)default: Default value, must be a string (optional)
Note: Although parameter values can only be strings, you may include formatted content (such as JSON strings) within the string, and parse it during usage.
JSON Object Handling
When passing JSON data, you need to handle it as a string:
Best Practices
-
Parameter Naming and Organization
- Use clear, descriptive parameter names
- Provide descriptions for all parameters
- Use default values appropriately
-
Template Design
- Keep templates reusable
- Use dynamic name generation
- Split complex templates appropriately
-
Error Handling
- Provide default values for critical parameters
- Use CEL interceptor to validate parameters
- Implement appropriate error handling mechanisms
Frequently Asked Questions
-
Parameter Parsing Errors
- Check parameter syntax
- Validate JSON object format
- Confirm parameter name matches
-
Resource Creation Failures
- Check resource template format
- Validate parameter values
- Review system permissions
-
Naming Conflicts
- Use generateName
- Implement uniqueness checks