@@ -26,6 +26,7 @@ import (
2626 "regexp"
2727 "sort"
2828 "strings"
29+ "time"
2930
3031 "k8s.io/apimachinery/pkg/util/wait"
3132
@@ -1172,6 +1173,8 @@ func (c *Reconciler) createTaskRun(ctx context.Context, taskRunName string, para
11721173
11731174 if rpt .PipelineTask .Timeout != nil {
11741175 tr .Spec .Timeout = rpt .PipelineTask .Timeout
1176+ } else if timeout := pipelineRunTimeout (ctx , pr , rpt , facts ); timeout != nil {
1177+ tr .Spec .Timeout = timeout
11751178 }
11761179
11771180 // taskRunSpec timeout overrides pipeline task timeout
@@ -1280,6 +1283,9 @@ func (c *Reconciler) createCustomRun(ctx context.Context, runName string, params
12801283 params = append (params , rpt .PipelineTask .Params ... )
12811284
12821285 taskTimeout := rpt .PipelineTask .Timeout
1286+ if taskTimeout == nil {
1287+ taskTimeout = pipelineRunTimeout (ctx , pr , rpt , facts )
1288+ }
12831289 // taskRunSpec timeout overrides pipeline task timeout
12841290 if taskRunSpec .Timeout != nil {
12851291 taskTimeout = taskRunSpec .Timeout
@@ -1512,6 +1518,33 @@ func (c *Reconciler) taskWorkspaceByWorkspaceVolumeSource(ctx context.Context, p
15121518 return binding
15131519}
15141520
1521+ // pipelineRunTimeout returns the applicable PipelineRun-level timeout for a task,
1522+ // based on whether it is a regular task or a finally task.
1523+ // It only returns a value when the PipelineRun timeout exceeds the global default
1524+ // (or is explicitly zero, meaning no timeout)
1525+ func pipelineRunTimeout (ctx context.Context , pr * v1.PipelineRun , rpt * resources.ResolvedPipelineTask , facts * resources.PipelineRunFacts ) * metav1.Duration {
1526+ var prTimeout * metav1.Duration
1527+ if facts .FinalTasksGraph != nil && rpt .IsFinalTask (facts ) {
1528+ prTimeout = pr .FinallyTimeout ()
1529+ } else {
1530+ prTimeout = pr .TasksTimeout ()
1531+ }
1532+
1533+ if prTimeout == nil {
1534+ return nil
1535+ }
1536+
1537+ if prTimeout .Duration == config .NoTimeoutDuration {
1538+ return prTimeout
1539+ }
1540+
1541+ defaultTimeout := time .Duration (config .FromContextOrDefaults (ctx ).Defaults .DefaultTimeoutMinutes ) * time .Minute
1542+ if prTimeout .Duration > defaultTimeout {
1543+ return prTimeout
1544+ }
1545+ return nil
1546+ }
1547+
15151548// combinedSubPath returns the combined value of the optional subPath from workspaceBinding and the optional
15161549// subPath from pipelineTask. If both is set, they are joined with a slash.
15171550func combinedSubPath (workspaceSubPath string , pipelineTaskSubPath string ) string {
0 commit comments