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

Unable to get tasks.TASK-NAME.status in finally section of the Pipeline #3762

Closed
dmitry-mightydevops opened this issue Feb 14, 2021 · 4 comments
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@dmitry-mightydevops
Copy link

Expected Behavior

Unable to get tasks.TASK-NAME.status in finally section of the Pipeline
Trying to follow this example - pipelinerun-task-execution-status.yaml

Essentially speaking I need to pass the value, which will be analyzed inside the slack-notification task based on the execution status of previous tasks. And if it fails - send a "Failure" notification, otherwise "Success" notification.

Here is my Pipeline:

apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
  name: backend-build-pipeline
spec:
  description: >-
    Pipeline will only build the image utilizing buildpacks and then send notification via slack.
    The deployment is done via argocd

  params:
    - name: application
    - name: head_commit
    - name: head_commit_message
    - name: pusher_name
    - name: pusher_email
    - name: pusher_avatar
    - name: pusher_url
    - name: repository_url
    - name: repository_ssh_url
    - name: branch
    - name: buildpack_builder_image
    - name: buildpack_runner_image
    - name: docker_registry
    - name: environment

  workspaces:
    - name: source

  resources:
    - name: app
      type: git
    - name: image
      type: image
    - name: kubernetes-repo
      type: git
  
  tasks:
    - name: buildpack
      taskRef:
        name: buildpack
      resources:
          inputs:
            - name: app
              resource: app
          outputs:
              - name: image
                resource: image
      params:
        - name: builder_image
          value: "$(params.buildpack_builder_image)"
        - name: run_image
          value: "$(params.buildpack_runner_image)"
        - name: docker_registry
          value: $(params.docker_registry)
        - name: cache
          value: $(params.application)-buildpacks-cache
        - name: environment
          value: "$(params.environment)"
      workspaces:
        - name: source
          workspace: source  

    - name: kustomize
      taskRef:
        name: kustomize
      resources:
        inputs:
          - name: kubernetes-repo
            resource: kubernetes-repo
      params:
        - name: branch
          value: $(params.branch)
        - name: image
          value: "$(params.docker_registry)/$(params.application):$(params.head_commit)"
        - name: environment
          value: "$(params.environment)"
      runAfter: 
        - buildpack
    
    - name: argocd-deploy
      taskRef:
        name: argocd-deploy
      params:
        - name : argocd_application_name
          value: "$(params.application)"
      runAfter: 
        - kustomize
    
  finally:
    - name: checker
      params:
        - name: buildpack_status
          value: "$(tasks.buildpack.status)"
        - name: kustomize_status
          value: "$(tasks.kustomize.status)"
        - name: argocd_deploy_status
          value: "$(tasks.argocd-deploy.status)"
      taskSpec:
        params:
          - name: buildpack_status
          - name: kustomize_status
          - name: argocd_deploy_status
        steps:
          - image: alpine
            name: verify-status
            script: |
              if [[ $(params.buildpack_status) != "Succeeded" ||  $(params.kustomize_status) != "Succeeded" || $(params.argocd_deploy_status) != "Succeeded" ]]; then
                exit 1;
              fi

    - name: slack-notification
      taskRef:
        name: slack-notification
      params:
        - name: status
          value: "$(tasks.checker.status)"
        - name: application
          value: "$(params.application)"
        - name: head_commit
          value: "$(params.head_commit)"
        - name: head_commit_message
          value: "$(params.head_commit_message)"
        - name: pusher_name
          value: "$(params.pusher_name)"
        - name: pusher_email
          value: "$(params.pusher_email)"
        - name: pusher_avatar
          value: "$(params.pusher_avatar)"
        - name: pusher_url
          value: "$(params.pusher_url)"
        - name: repository_url
          value: "$(params.repository_url)"
        - name: branch
          value: "$(params.branch)"
        - name: environment
          value: "$(params.environment)"

Actual Behavior

[status : verify-status] + tasks.buildpack.status
[status : verify-status] /tekton/scripts/script-0-6xn95: line 3: tasks.buildpack.status: not found
[status : verify-status] + tasks.kustomize.status
[status : verify-status] /tekton/scripts/script-0-6xn95: line 3: tasks.kustomize.status: not found
[status : verify-status] + tasks.argocd-deploy.status
[status : verify-status] /tekton/scripts/script-0-6xn95: line 3: tasks.argocd-deploy.status: not found
[status : verify-status] + '[[' '!=' Succeeded -o '!=' Succeeded -o '!=' Succeeded ]]
[status : verify-status] sh: Succeeded: unknown operand

Additional Info

  • Kubernetes version:
✗  kubectl version  
Client Version: version.Info{Major:"1", Minor:"18+", GitVersion:"v1.18.9-eks-d1db3c", GitCommit:"d1db3c46e55f95d6a7d3e5578689371318f95ff9", GitTreeState:"clean", BuildDate:"2020-10-20T22:21:03Z", GoVersion:"go1.13.15", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"18+", GitVersion:"v1.18.9-eks-d1db3c", GitCommit:"d1db3c46e55f95d6a7d3e5578689371318f95ff9", GitTreeState:"clean", BuildDate:"2020-10-20T22:18:07Z", GoVersion:"go1.13.15", Compiler:"gc", Platform:"linux/amd64"}
  • Tekton Pipeline version:
➜ tkn version                                             
Client version: 0.15.0
Pipeline version: v0.15.2
Triggers version: v0.11.2
Dashboard version: v0.14.0
@dmitry-mightydevops dmitry-mightydevops added the kind/bug Categorizes issue or PR as related to a bug. label Feb 14, 2021
@jerop
Copy link
Member

jerop commented Feb 16, 2021

@dmitry-mightydevops please note that access to execution status of non-finally tasks in finally tasks was added in tekton pipelines v0.20.0 but you're using tekton pipelines v0.15.2

it also looks like you're trying to use the status of finally task checker in another finally task slack-notification, and that doesn't work because:

  • all finally tasks execute in parallel, so slack-notification would not wait for checker to finish executing, read more
  • finally tasks can access and use the execution status of non-finally tasks only, they don't have access to the execution status of other finally tasks, read more

your use case would be best solved by using an aggregate status of non-finally tasks, which is something that @pritidesai is working on

another feature that could be useful is when expressions in finally tasks which will be included in the next release coming out this week, which can be used to solve this use case as such before aggregate status is available:

apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
  name: backend-build-pipeline
spec:

  tasks:
    - name: buildpack
      taskRef:
        name: buildpack
      ...
    - name: kustomize
      taskRef:
        name: kustomize
      runAfter: 
        - buildpack
      ...
    - name: argocd-deploy
      taskRef:
        name: argocd-deploy
      runAfter: 
        - kustomize
      ...

  finally:
    - name: slack-notification-succeeded
      when:
        - input: "Failed"
          operator: notin
          values:
            - "$(tasks.buildpack.status)"
            - "$(tasks.kustomize.status)"
            - "$(tasks.argocd-deploy.status)"
      taskRef:
        name: slack-notification
      params:
        - name: status
          value: "Succeeded"
      ...
    - name: slack-notification-failed
      when:
        - input: "Failed"
          operator: in
          values:
            - "$(tasks.buildpack.status)"
            - "$(tasks.kustomize.status)"
            - "$(tasks.argocd-deploy.status)"
      taskRef:
        name: slack-notification
      params:
        - name: status
          value: "Failed"
      ...

alternatively, we know argo-deploy task can only be successful if buildpack and kustomize tasks are successful as well, so we could only check the status of argo-deploy only, as such:

apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
  name: backend-build-pipeline
spec:

  tasks:
    - name: buildpack
      taskRef:
        name: buildpack
      ...
    - name: kustomize
      taskRef:
        name: kustomize
      runAfter: 
        - buildpack
      ...
    - name: argocd-deploy
      taskRef:
        name: argocd-deploy
      runAfter: 
        - kustomize
      ...

  finally:
    - name: slack-notification
      taskRef:
        name: slack-notification
      params:
        - name: status
          value: "$(tasks.argocd-deploy.status)"
      ...

so I don't think this is a bug, but an additional use case for providing the aggregate status of non-finally tasks to finally tasks

@dmitry-mightydevops
Copy link
Author

@jerop thank you for the excellent explanation!

@pritidesai
Copy link
Member

thanks @jerop will add this as one of the use cases for accessing aggregate status of all the tasks from finally #1020.

@Monishkumar12
Copy link

Hello , I didn't get the finally task properly .
May i know how to attach task logs for every notifications we will send.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

No branches or pull requests

4 participants