pipeline icon indicating copy to clipboard operation
pipeline copied to clipboard

Weird behavior of the aggregate task status in finally block

Open thomascube opened this issue 2 years ago • 1 comments

Expected Behavior

According to the documentation we use the $(tasks.status) as input for a when condition to guard the execution of a finally task.

We'd expect the following task to execute if all pipeline tasks complete successfully:

    finally:
      - name: finally-echo
        params:
          - name: SCRIPT
            value: "echo 'Finally $(tasks.status)'"
        taskRef:
          kind: Task
          name: custom-exec
        when:
          - input: $(tasks.status)
            operator: in
            values:
              - Completed
              - Succeeded

Actual Behavior

The finally-echo task is not executed.

When "inverting" the when condition as follows, the finally task is executed:

    when:
      - input: $(tasks.status)
        operator: notin
        values:
          - Failed

The log output of the task however is "Finally Completed"

Additional Info

  • Kubernetes version:

    Tekton on Openshift (via Openshift Pipelines Operator v1.7.2)

    Client Version: 4.10.6
    Server Version: 4.10.28
    Kubernetes Version: v1.23.5+012e945
    
  • Tekton Pipeline version:

    Tekton Pipelines: v0.33.2
    

Please find attached three pipelineruns illustrating the issue.

finally-task-status-pr.zip

thomascube avatar Sep 08 '22 11:09 thomascube

I tried that, it workd. The yaml file is:

# simple-multi-task-pipeline.yaml
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
  name: pipelinerun-test
spec:
  pipelineSpec:
    tasks:
      - name: hello
        taskSpec:
          steps:
          - image: alpine
            script: |
              #!/bin/sh
              echo "Hello world!"
  
      - name: goodbye
        runAfter:
          - hello
        taskSpec:
          steps:
          - image: alpine
            script: |
              #!/bin/sh
              echo "Goodbye world!"
    finally:
      - name: notify-any-failure # executed only when one or more tasks fail
        params:
        - name: status
          value: "$(tasks.status)"
        when:
          - input: $(tasks.status)
            operator: in
            values: ["Succeeded","Completed"]
        taskRef:
          name: task-with-parameters
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: task-with-parameters
spec:
  params:
  - name: status
    type: string
  steps:
    - name: do-the-clone
      image: alpine
      command: ["sh","-c"]
      args: [
        "echo '$(params.status)'"
      ]
  

cleverhu avatar Sep 11 '22 16:09 cleverhu

@cleverhu Running both my example and your test case again on my Openshift cluster (now on version 4.10.36) shows the successful execution of the finally tasks. I'm no longer able to reproduce the reported problem myself. No idea what changed but this issue can be closed. My apologies for the noise!

thomascube avatar Oct 28 '22 19:10 thomascube