Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access reason from the execution status of a taskRun in finally #8110

Open
pritidesai opened this issue Jul 10, 2024 · 0 comments
Open

Access reason from the execution status of a taskRun in finally #8110

pritidesai opened this issue Jul 10, 2024 · 0 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature.

Comments

@pritidesai
Copy link
Member

pritidesai commented Jul 10, 2024

Feature request

A finally task can access both the reason and status of a pipelineTask from the tasks section.

Use case

  • Perform a range of tests (such as static scans, unit tests, dynamic scans, compliance checks, etc.) within a pipeline. Upload the results of all scans and return a failure if any mandatory scans are unsuccessful.

When these tests are executed as part of a task called checks, compliance checks must pass in prod but can be ignored in dev mode. While the finally task can access the status of the checks, it cannot distinguish between modes or decide whether to report a failure.

Running checks with onError set to continue in dev mode can report success. In this context, success means informing the developer about the failed checks but not preventing the code from being merged into the dev branch.

Running checks with onError set to stopAndFail in prod mode must report failure. This means notifying both the developer and the release manager about the failed checks and preventing the code from being merged into the prod branch.

When onError is set to either continue or stopAndFail and the task fails, the status remains Failed, making it indistinguishable whether the failure was allowed or not. However, when onError is set to continue, the reason is assigned FailureIgnored. This additional information can be used to identify that the checks failed, but the failure can be ignored.

When designing the onError feature at the step level, the step exit code is made available to subsequent steps. Similarly, we are seeking a method to classify a task that failed but had FailureIgnored.

A sample finally task:

    finally:
      - name: finish
        params:
          - name: echo-continue-task-status
            value: $(tasks.echo-continue.status)
          - name: echo-fail-task-status
            value: $(tasks.echo-fail.status)
          - name: echo-continue-task-reason
            value: $(tasks.echo-continue.reason)
          - name: echo-fail-task-reason
            value: $(tasks.echo-fail.reason)
        taskSpec:
          steps:
            - name: check
              image: docker.io/library/alpine
              script: |
                echo "this is a finish task"
                echo "echo-continue Task Status:"
                echo $(params.echo-continue-task-status)
                echo "echo-fail Task Status:"
                echo $(params.echo-fail-task-status)
                echo "echo-continue Task Reason:"
                echo $(params.echo-continue-task-reason)
                echo "echo-fail Task Reason:"
                echo $(params.echo-fail-task-reason)

Logs from this finally task:

k logs pipelinerun-with-failing-task-8dvch-finish-pod
Defaulted container "step-check" out of: step-check, prepare (init), place-scripts (init)
this is a finish task
echo-continue Task Status:
Failed
echo-fail Task Status:
Failed
echo-continue Task Reason:
FailureIgnored
echo-fail Task Reason:
Failed

References:

/kind feature

@pritidesai pritidesai added the kind/feature Categorizes issue or PR as related to a new feature. label Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

No branches or pull requests

1 participant