PipelineRuns
A PipelineRun is a Kubernetes Custom Resource that instantiates a Pipeline for execution. PipelineRuns are responsible for executing the Tasks defined in a Pipeline and managing their lifecycle, providing a way to run end-to-end CI/CD workflows.
TOC
Why PipelineRuns are Needed
CI/CD Workflow Challenges
In CI/CD systems, there are several challenges related to workflow execution:
- Workflow Orchestration: Need to coordinate multiple tasks in a specific order
- Resource Coordination: Need to manage resources across multiple tasks
- Data Sharing: Need to share data between tasks in a workflow
- Execution Tracking: Need to track the progress of the entire workflow
- Error Handling: Need to handle failures at both task and workflow levels
- Auditability: Need to maintain a record of all workflow executions
Tekton's Solution
Tekton PipelineRuns address these challenges by:
- Workflow Instance: Each PipelineRun represents a single execution of a Pipeline with specific inputs
- Orchestration: PipelineRuns manage the execution order of Tasks based on dependencies
- Resource Binding: PipelineRuns bind actual resources to Pipeline requirements
- Status Tracking: PipelineRuns track the status of each Task's execution
- Result Propagation: PipelineRuns enable sharing results between Tasks
- Kubernetes Integration: PipelineRuns leverage Kubernetes for resource management and scheduling
Advantages
- Isolation: Each PipelineRun executes independently, allowing parallel execution of the same Pipeline
- Traceability: PipelineRuns provide detailed execution history and logs
- Flexibility: PipelineRuns can override Pipeline parameters and workspace bindings
- Reusability: The same Pipeline can be executed with different inputs via different PipelineRuns
- Integration: PipelineRuns can be triggered by various systems through Kubernetes API
- Observability: PipelineRun status and logs can be monitored through Kubernetes tools
Scenarios
PipelineRuns are useful in various scenarios, including:
- Application CI/CD: Building, testing, and deploying applications
- Infrastructure as Code: Provisioning and managing infrastructure
- Release Management: Coordinating complex release processes
- Scheduled Workflows: Running workflows on a schedule
- Event-Driven Workflows: Triggering workflows in response to external events
Constraints and Limitations
- PipelineRuns execute within a single Kubernetes cluster
- Once started, PipelineRun parameters cannot be modified
- PipelineRuns have limited retry capabilities for failed Tasks
- PipelineRun execution time is limited by the Kubernetes pod timeouts
- PipelineRuns cannot be paused once they start executing (except with "finally" tasks)
Principles
PipelineRun Execution Model
When a PipelineRun is created:
- Tekton validates the PipelineRun specification
- Tekton creates TaskRuns for each Task in the Pipeline
- TaskRuns are executed based on their dependencies
- Results from Tasks are collected and can be used by subsequent Tasks
- The PipelineRun status is updated as each TaskRun completes
- "Finally" Tasks are executed after all other Tasks complete or fail
- The PipelineRun completes when all TaskRuns complete
PipelineRun Status
The PipelineRun status provides detailed information about the execution:
- Overall status (Running, Succeeded, Failed, etc.)
- Start and completion times
- Individual TaskRun statuses
- Task results
- Reason for failure (if applicable)
- TaskRun names for accessing logs
Configuration Examples
Basic PipelineRun Example
PipelineRun with Embedded Pipeline Definition
Important Parameters
Timeout
Timeout allows setting a maximum duration for PipelineRun execution.
Use Cases
- Preventing long-running Pipelines from consuming resources indefinitely
- Ensuring CI/CD workflows complete within a reasonable timeframe
- Handling hung or deadlocked Tasks
- Setting different timeout limits for different phases of pipeline execution
Principles
Timeouts are:
- Specified in the PipelineRun specification using the
timeoutsfield (the legacytimeoutfield is deprecated) - Applied to the entire PipelineRun execution or specific sections (tasks, finally)
- Measured from the start of the first Task to the completion of the last Task
- Result in PipelineRun failure if exceeded
- Must follow the constraint:
timeouts.pipeline >= timeouts.tasks + timeouts.finally - Important: If any sub-field is set to "0", there is no timeout for that section. To set
timeouts.tasksortimeouts.finallyto "0", you must also settimeouts.pipelineto "0"
Timeout Fields
- pipeline: Maximum duration for the entire PipelineRun
- tasks: Maximum duration for all non-finally tasks
- finally: Maximum duration for all finally tasks
Configuration Examples
Example 1: Standard timeout configuration
Example 2: No timeout for tasks and finally (requires pipeline timeout to be 0)
Note:
- Example 1 follows the constraint where
pipeline (1h) >= tasks (45m) + finally (15m) - Example 2 shows how to disable timeouts by setting all values to "0"
ServiceAccount
ServiceAccount allows specifying the Kubernetes ServiceAccount to use for authentication.
Use Cases
- Providing credentials for accessing private container registries
- Authenticating with cloud providers
- Authorizing access to Kubernetes resources
- Providing credentials for Git operations
Principles
ServiceAccounts:
- Can be specified at the PipelineRun level for all Tasks
- Can be mapped to specific Tasks using taskRunSpecs
- Provide credentials through Kubernetes secrets
- Enable secure access to external resources
Configuration Example
Pod Template
Pod Template allows specifying a Pod template to use as the basis for the configuration of the Pod that executes each Task.
For more information about Pod Templates, please refer to Pod Templates.
Use Cases
- Setting node selectors for specific hardware requirements
- Configuring tolerations for dedicated nodes
- Specifying security contexts for enhanced security
- Setting resource limits and requests at the Pod level
- Configuring affinity rules for better resource utilization
- Adding custom annotations or labels to Pods
Principles
Pod Templates:
- Are applied to all Tasks in the PipelineRun unless overridden by taskRunSpecs
- Follow Kubernetes Pod template specifications
- Can be overridden by Task-specific configurations in taskRunSpecs
- Enable consistent Pod configuration across all Tasks in a PipelineRun
- Support all standard Kubernetes Pod template fields
Configuration Example
TaskRunSpecs
TaskRunSpecs allow customizing individual TaskRun configurations within a PipelineRun by specifying a list of PipelineTaskRunSpec which enables setting ServiceAccountName, Pod template, and Metadata for each task.
Use Cases
- Applying different ServiceAccounts to different Tasks for fine-grained access control
- Setting Task-specific Pod templates to meet different resource or security requirements
- Configuring Task-specific metadata for better organization and tracking
- Overriding global PipelineRun configurations for specific Tasks
- Applying different compute resources or node selectors to different stages of the Pipeline
Principles
TaskRunSpecs:
- Override the Pod template set for the entire Pipeline
- Allow fine-grained control over Task execution environments
- Can be used to meet specific security, resource, or scheduling requirements
- Enable different configurations for different stages of the Pipeline
- Support all standard Kubernetes Pod template specifications
- Can be combined with global PipelineRun configurations
Configuration Fields
Each TaskRunSpec supports the following fields:
- pipelineTaskName: The name of the Pipeline task to apply the configuration to
- serviceAccountName: The ServiceAccount to use for this specific Task
- podTemplate: Pod template configuration specific to this Task
- metadata: Metadata configuration for the TaskRun
Configuration Examples
Example 1: Basic TaskRunSpecs with ServiceAccount and Pod Template
Example 2: TaskRunSpecs with Advanced Pod Configuration
Example 3: TaskRunSpecs with Metadata Configuration
Example 4: TaskRunSpecs Overriding Global Pod Template
TaskRunSpecs can override the global Pod template set at the PipelineRun level:
Workspaces
Workspaces allow sharing data between Tasks in a Pipeline.
Use Cases
- Sharing source code between build and test Tasks
- Passing build artifacts to deployment Tasks
- Sharing configuration files across multiple Tasks
- Persisting data between Pipeline executions
Principles
Workspaces:
- Are declared in the Pipeline and bound in the PipelineRun
- Can be backed by various volume types (PVC, ConfigMap, Secret, etc.)
- Enable data sharing without direct dependencies
- Support different access modes (ReadOnly, ReadWrite)
Configuration Example
PipelineRun Status Management
Monitoring Execution Status
The status field of a PipelineRun provides detailed information about the execution progress:
Cancelling a PipelineRun
To cancel a running PipelineRun, update its spec.status field:
This immediately terminates all running TaskRuns and does not execute pending Tasks or finally Tasks.
Gracefully Stopping a PipelineRun
To gracefully stop a PipelineRun, allowing finally Tasks to execute:
This completes currently running Tasks but does not start new ones, except for finally Tasks.