tektoncd / pipeline

A cloud-native Pipeline resource.
https://tekton.dev
Apache License 2.0
8.48k stars 1.78k forks source link

pipelinerun-with-when-expressions #8163

Open ForcemCS opened 3 months ago

ForcemCS commented 3 months ago

I don't understand why my finally task isn't executing:

root@master01:~/v1.30/12-tekton/clone-build-helm# kubectl get   pods  
NAME                                             READY   STATUS      RESTARTS       AGE
clone-build-helm-fqwfv-build-push-pod            0/2     Completed   0              4m14s
clone-build-helm-fqwfv-fetch-source-pod          0/1     Completed   0              4m24s
clone-build-helm-fqwfv-helm-install-middle-pod   0/1     Completed   0              42s

root@master01:~/v1.30/12-tekton/clone-build-helm# cat   01-pipeline.yaml 
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
  name: clone-build-helm
spec:
  description: |
    This pipeline clones a git repo, builds a Docker image with Kaniko and
    pushes it to a registry    
  params:
  - name: repo-url
    type: string
    description: GitLab的项目地址
  - name: subdirectory
    type: string
  - name: gitrevision-tag
    type: string
    description: 项目分支名称
   ....
  finally:
  - name: send-wechat-notification  # when expression using execution status, evaluates to false          
    when:
      - input: "$(tasks.status)"
        operator: in
        values: ["Completed"]
    taskSpec:
      steps:
        - name: send-notification
          image: curlimages/curl
          script: |
            #!/usr/bin/env sh
              curl 'https://qyapi.weixin.qq.com/xxxxxxxxxxxx' \
                                 -H 'Content-Type: application/json' \
                                 -d '
                                  {
                                      "msgtype": "text",
                                      "text": {
                                          "content": "中台前端发布完成",
                                                  "mentioned_list":["WuKui","@all"]
                                      }
                                  }'
l-qing commented 2 months ago

To see why the when check was skipped, you should be able to find it in the status of your PipelineRun's YAML.

l-qing commented 2 months ago

Suggestion:

      when:
        - input: $(tasks.status)
          operator: in
          values: ["Succeeded", "Completed"]

Ref: https://tekton.dev/docs/pipelines/pipelines/#using-aggregate-execution-status-of-all-tasks

Status Description
Succeeded all tasks have succeeded
Failed one ore more tasks failed
Completed all tasks completed successfully including one or more skipped tasks