pipeline
pipeline copied to clipboard
`context.task.retry-count` returns value zero all the time
Expected Behavior
context.task.retry-count should give the actual retry count value
Actual Behavior
context.task.retry-count returns value zero all the time
Steps to Reproduce the Problem
- Create a Pipeline as described in this section
- Start the pipeline and observe the logs of pipelinerun
Additional Info
-
Kubernetes version:
Output of
kubectl version:Client Version: v1.24.6 Kustomize Version: v4.5.4 Server Version: v1.24.0+3882f8f -
Tekton Pipeline version:
Output of
tkn versionorkubectl get pods -n tekton-pipelines -l app=tekton-pipelines-controller -o=jsonpath='{.items[0].metadata.labels.version}'
tkn version ✔ 11:06:19 AM
Client version: 0.24.0
Pipeline version: v0.37.4
Triggers version: v0.20.2
Operator version: v0.60.1
thank you @VeereshAradhya for reporting this issue 👍
What API version are you running with, v1beta1? I am a little surprised since we have an example which validates this context variable. Do you observe $(context.pipelineTask.retries) set to zero as well? otherwise this example should fail the CI, right? 🤔
@pritidesai I tried the given example and observed that the "$(context.task.retry-count)" works fine in the embedded spec that the example contains but fails when we create task and pipeline separately.
I am attaching the task and pipeline yaml files
Task:
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: retry-task-bug
spec:
params:
- name: pipelineTask-retries
- name: pipelineTask-retry-count
default: "$(context.task.retry-count)"
steps:
- name: retry-me
image: alpine:3.12.0
script: |
#!/usr/bin/env sh
if [ "$(params.pipelineTask-retry-count)" == "$(params.pipelineTask-retries)" ]; then
echo "This is the last retry."
exit 0;
fi
echo "The PipelineTask has retried $(context.task.retry-count) times."
echo "pipelineTask-retries = $(params.pipelineTask-retries)"
exit 1
Pipeline:
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: retry-pipeline-bug
spec:
tasks:
- name: retry-task-bug
params:
- name: pipelineTask-retries
value: "$(context.pipelineTask.retries)"
taskRef:
name: retry-task-bug
retries: 5
@VeereshAradhya do you mean task and pipelinerun like this:
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: retry-task-bug
spec:
params:
- name: pipelineTask-retries
default: "$(context.pipelineTask.retries)"
- name: pipelineTask-retry-count
default: "$(context.task.retry-count)"
steps:
- name: retry-me
image: alpine:3.12.0
script: |
#!/usr/bin/env sh
if [ "$(params.pipelineTask-retry-count)" == "$(params.pipelineTask-retries)" ]; then
echo "This is the last retry."
exit 0;
fi
echo "The PipelineTask has retried $(context.task.retry-count) times."
echo "pipelineTask-retries = $(params.pipelineTask-retries)"
exit 1
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: retry-pipeline-bug
spec:
pipelineSpec:
tasks:
- name: retry-tasks
retries: 5
taskRef:
name: retry-task-bug
get results
pods:
NAME READY STATUS RESTARTS AGE
retry-pipeline-bug-retry-tasks-pod 0/1 Error 0 5m11s
retry-pipeline-bug-retry-tasks-pod-retry1 0/1 Error 0 5m6s
retry-pipeline-bug-retry-tasks-pod-retry2 0/1 Error 0 5m1s
retry-pipeline-bug-retry-tasks-pod-retry3 0/1 Error 0 4m55s
retry-pipeline-bug-retry-tasks-pod-retry4 0/1 Error 0 4m50s
retry-pipeline-bug-retry-tasks-pod-retry5 0/1 Error 0 4m45s
kubectl logs retry-pipeline-bug-retry-tasks-pod-retry5 -c step-retry-me:
/tekton/scripts/script-0-72rw8: line 2: context.pipelineTask.retries: not found
The PipelineTask has retried 0 times.
pipelineTask-retries =
/tekton/scripts/script-0-72rw8: line 7: context.pipelineTask.retries: not found
@chengjoey Sorry for the delayed response. You are trying to access a pipeline variable ("$(context.task.retry-count)") inside a task definition, it does not if it is not an embedded spec.
You can reproduce the issue by creating the task and pipeline from the spec that I provided and use the below pipelinerun spec to start the pipelinerun
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: retry-pipeline-bug-run-
spec:
pipelineRef:
name: retry-pipeline-bug
Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale with a justification.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close with a justification.
If this issue should be exempted, mark the issue as frozen with /lifecycle frozen with a justification.
/lifecycle stale
Send feedback to tektoncd/plumbing.
Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten with a justification.
Rotten issues close after an additional 30d of inactivity.
If this issue is safe to close now please do so with /close with a justification.
If this issue should be exempted, mark the issue as frozen with /lifecycle frozen with a justification.
/lifecycle rotten
Send feedback to tektoncd/plumbing.
Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen with a justification.
Mark the issue as fresh with /remove-lifecycle rotten with a justification.
If this issue should be exempted, mark the issue as frozen with /lifecycle frozen with a justification.
/close
Send feedback to tektoncd/plumbing.
@tekton-robot: Closing this issue.
In response to this:
Rotten issues close after 30d of inactivity. Reopen the issue with
/reopenwith a justification. Mark the issue as fresh with/remove-lifecycle rottenwith a justification. If this issue should be exempted, mark the issue as frozen with/lifecycle frozenwith a justification./close
Send feedback to tektoncd/plumbing.
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
I faced this same issue, can we reopen it?
/reopen
/reopen