StepActions
A StepAction is the reusable and scriptable unit of work that is performed by a Step in Tekton Pipelines. StepActions allow you to define containerized operations that can be referenced and reused across different Tasks.
TOC
Why StepActions are NeededTraditional Task ChallengesTekton's SolutionAdvantagesScenariosConstraints and LimitationsPrinciplesStepAction Execution ModelReferencing ModelConfiguration ExamplesBasic StepAction ExampleReferencing a StepAction in a TaskImportant ParametersParametersUse CasesPrinciplesConfiguration ExampleResultsUse CasesPrinciplesConfiguration ExampleWorkingDirUse CasesConfiguration ExampleSecurityContextUse CasesConfiguration ExampleVolumeMountsUse CasesConfiguration ExampleWhen ExpressionsUse CasesConfiguration ExampleRemote StepActionsUse CasesConfiguration ExampleReferencesWhy StepActions are Needed
Traditional Task Challenges
Before StepActions, Tasks faced several limitations:
- Reusability: Steps defined within Tasks couldn't be easily extracted and reused
- Maintainability: Common step logic had to be duplicated across different Tasks
- Versioning: Difficult to version control individual steps separately from Tasks
- Consistency: Hard to ensure consistent implementation of common operations
Tekton's Solution
StepActions address these challenges by:
- Step-Level Reusability: Encapsulate common operations as reusable components
- Declarative Definition: Define StepActions as Kubernetes Custom Resources
- Parameterization: Accept parameters to customize behavior
- Result Emission: Produce results that can be consumed by other steps
- Resource Control: Define resource requirements separately from the Tasks
Advantages
- Modularity: Break down complex operations into reusable components
- Consistency: Ensure identical implementation of common operations across Tasks
- Maintainability: Update a StepAction once and all referencing Tasks benefit
- Clarity: Separate the definition of what to do (StepAction) from when to do it (Step)
- Versioning: Version control StepActions independently from Tasks
Scenarios
StepActions are useful in various scenarios, including:
- Common Operations: Git clone, image build, security scanning
- Standardized Tools: Linters, formatters, test runners
- Organization-Specific Logic: Custom deployment procedures, approval workflows
- Shared Utilities: Version generation, configuration validation
- Integration Components: Service interaction, API operations
Constraints and Limitations
- StepActions can only be used within Steps
- Cannot pass Step Results between Steps
- Parameters cannot be directly used in scripts (must use environment variables)
- StepActions cannot run stand-alone (unlike TaskRuns or PipelineRuns)
- Requires the
enable-step-actionsfeature flag to be set to "true"
Principles
StepAction Execution Model
When a StepAction is referenced by a Step:
- The Step provides the necessary context and parameters
- The StepAction defines the container image and execution logic
- The Step can override certain aspects like resources and timeout
- The referenced StepAction executes its defined commands or script
- Results from the StepAction can be consumed by subsequent steps
Referencing Model
StepActions are not components of Steps. Instead:
- A Step is an actionable component that can reference a StepAction
- The Step provides orchestration and context
- The StepAction provides reusable logic
- A Step can reference local or remote StepActions
Configuration Examples
Basic StepAction Example
Referencing a StepAction in a Task
Important Parameters
Parameters
Parameters allow StepActions to be customized when referenced by Steps.
Use Cases
- Configuring connection details
- Specifying targets or destinations
- Setting operational flags
- Defining version information
- Controlling behavior
Principles
Parameters in StepActions are:
- Declared in the StepAction specification
- Can have default values
- Passed from the referencing Step
- Support string, array, and object types
- Cannot be directly used in scripts (should be used through environment variables)
Configuration Example
Results
Results allow StepActions to emit values that can be consumed by other Steps or Tasks.
Use Cases
- Sharing build information
- Passing generated identifiers
- Communicating status information
- Providing artifact locations
Principles
Results are:
- Declared in the StepAction specification
- Written to a specific file path by the StepAction
- Made available to subsequent Steps or Tasks
Configuration Example
WorkingDir
WorkingDir allows specifying the working directory for a StepAction.
Use Cases
- Setting the correct context for operations
- Ensuring commands run in the right location
- Providing consistency across StepAction usage
Configuration Example
SecurityContext
SecurityContext allows configuring the security settings for a StepAction.
Use Cases
- Setting container permissions
- Configuring user and group IDs
- Managing security constraints
Configuration Example
VolumeMounts
VolumeMounts allow StepActions to access external storage.
Use Cases
- Accessing configuration files
- Storing persistent data
- Sharing information between steps
Configuration Example
When Expressions
When Expressions allow controlling whether a Step that references a StepAction should execute.
Use Cases
- Conditional execution based on parameters
- Skipping steps based on workspace availability
- Controlling workflow based on previous step results
Configuration Example
Remote StepActions
StepActions can be referenced from remote locations such as git repositories.
Use Cases
- Centralized StepAction management
- Version controlling StepActions
- Sharing StepActions across organizations