You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Openshift/Tekton Pipeline:符合条件却异常跳过任务问题排查

问题解决:Tekton Pipeline do-stuff 任务被跳过的原因

你的问题主要出在任务结果引用错误和条件匹配细节上,具体如下:

1. 任务名称引用拼写错误

在Pipeline的do-stuff任务when条件里,你引用的是$(tasks.test-repo.results.passed),但你定义的前置任务实例名称是test-repo-task,test-repo是Task本身的名称,不是Pipeline里的任务实例名。正确的引用应该是:

$(tasks.test-repo-task.results.passed)

同样,show-task-result里的$(tasks.test-repo-docs.results.passed)也是笔误,应该改成$(tasks.test-repo-task.results.passed)——这是导致条件不生效的核心原因之一。

2. when条件的匹配逻辑优化

即使修正了引用,还要注意值的大小写和操作符选择:

  • 用PowerShell的Set-Content -Value $true写入结果时,实际生成的是大写的"True"字符串。如果你的when条件里values用的是小写'true',会因为大小写不匹配导致条件不成立。
  • 对于单一值的匹配场景,用equals操作符比in更直观,避免数组匹配的额外复杂度:
    when:
      - input: $(tasks.test-repo-task.results.passed)
        operator: equals
        value: 'True'
    

如果你想统一用小写,也可以修改PowerShell脚本,直接写入小写字符串:

Set-Content -Path $(results.passed.path) -Value 'true' -Force

对应的when条件改为:

when:
    - input: $(tasks.test-repo-task.results.passed)
      operator: equals
      value: 'true'

修正后的完整关键代码

修正后的do-stuff任务

- name: do-stuff
  runAfter:
    - test-repo-task
  taskRef:
    kind: Task
    name: other-task
  when:
    - input: $(tasks.test-repo-task.results.passed)
      operator: equals
      value: 'True'

修正后的show-task-result任务

- name: show-task-result
  params:
    - name: PS_COMMANDS
      value: echo "$(tasks.test-repo-task.results.passed)"
    - name: PATH_CONTEXT
      value: .
    - name: POWERSHELL_IMAGE
      value: mcr.microsoft.com/powershell:latest
  runAfter:
    - do-stuff
  taskRef:
    kind: ClusterTask
    name: powershell

内容的提问来源于stack exchange,提问作者jeremywat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 03:56:19