The Matrix.groovy pipeline now supports timeout configuration for shell run actions. This allows you to set timeouts for individual steps or globally for all steps.
Set a default timeout for all steps in your YAML configuration:
job: my_job
timeout_minutes: 60 # 60 minutes default timeout for all steps
steps:
- name: step1
run: "echo hello"
# Uses global timeout of 60 minutesOverride the global timeout for individual steps:
steps:
- name: quick_step
run: "echo hello"
timeout: 5 # 5 minutes timeout
- name: long_step
run: "sleep 3600"
timeout: 10 # 10 minutes timeout - will timeout before completionUse environment variables or template variables for timeout values:
env:
DEFAULT_TIMEOUT: 30
LONG_TIMEOUT: 120
steps:
- name: template_step
run: "echo using template timeout"
timeout: "${DEFAULT_TIMEOUT}" # Uses environment variableWhen a step times out:
- Timeout Exception: The step will throw a timeout exception
- onfail Handler: If configured, the
onfailcommand will execute - always Handler: If configured, the
alwayscommand will execute - Pipeline Failure: The step will be marked as failed
steps:
- name: timeout_with_handlers
run: "sleep 3600" # Long running command
timeout: 5 # 5 minutes timeout
onfail: "echo 'Step timed out - cleaning up'"
always: "echo 'Always executed regardless of timeout'"-
run_shell(cmd, title, retOut=false, timeout_minutes=null)- Added
timeout_minutesparameter - Wraps shell execution in
timeout()block when timeout is specified
- Added
-
run_step_shell(image, cmd, title, oneStep, config)- Retrieves timeout value from step configuration using
getConfigVal() - Passes timeout to
run_shell()function - Applies timeout to
onfailandalwayshandlers
- Retrieves timeout value from step configuration using
The timeout value is resolved using the existing getConfigVal() function:
- Checks step-specific timeout first
- Falls back to global timeout if step timeout is not specified
- Supports template variable resolution (e.g.,
${VARIABLE}) - Returns
nullif no timeout is configured (no timeout applied)
- Existing YAML configurations without timeout settings continue to work unchanged
- Steps without timeout configuration run without time limits (original behavior)
- All existing step properties (
run,onfail,always, etc.) continue to work
steps:
- name: basic_timeout
run: "long_running_command"
timeout: 30env:
BUILD_TYPE: "release"
steps:
- name: conditional_timeout
run: "build_command"
timeout: "${BUILD_TYPE == 'release' ? '120' : '30'}"timeout: 60 # Global default
steps:
- name: quick_step
run: "echo quick"
timeout: 5 # Override for this step
- name: normal_step
run: "echo normal"
# Uses global timeout of 60 minutesThe test_timeout_example.yaml file demonstrates various timeout scenarios:
- Global timeout configuration
- Step-specific timeouts
- Template variable usage
- Error handling with
onfailandalwayshandlers