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 NeededCI/CD Workflow ChallengesTekton's SolutionAdvantagesScenariosConstraints and LimitationsPrinciplesPipelineRun Execution ModelPipelineRun StatusConfiguration ExamplesBasic PipelineRun ExamplePipelineRun with Embedded Pipeline DefinitionImportant ParametersTimeoutUse CasesPrinciplesConfiguration ExampleServiceAccountUse CasesPrinciplesConfiguration ExampleTaskRunSpecsUse CasesPrinciplesConfiguration ExampleWorkspacesUse CasesPrinciplesConfiguration ExamplePipelineRun Status ManagementMonitoring Execution StatusCancelling a PipelineRunGracefully Stopping a PipelineRunReferencesWhy 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
Principles
Timeouts are:
- Specified in the PipelineRun specification
- 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
Configuration Example
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
TaskRunSpecs
TaskRunSpecs allow customizing individual TaskRun configurations within a PipelineRun.
Use Cases
- Applying different ServiceAccounts to different Tasks
- Setting Task-specific Pod templates
- Configuring Task-specific timeouts
- Applying Task-specific compute resources
Principles
TaskRunSpecs:
- Override default PipelineRun configurations for specific Tasks
- Allow fine-grained control over Task execution environments
- Can be used to meet specific security or resource requirements
- Enable different configurations for different stages of the Pipeline
Configuration Example
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.