我有一个 Openshift/Tekton 管道。我有一个任务,如果某些测试通过,则输出 true/false
passed
结果:
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: test-repo
spec:
results:
- name: passed
type: string
steps:
- image: 'mcr.microsoft.com/powershell:latest'
name: repo-passed
script: |
#!/usr/bin/env pwsh
if (Run-Tests){
Set-Content -Path $(results.passed.path) -Value $true -Force
}
如果上述任务返回“True”,我应该运行第二个任务,第三个任务输出
passed
结果用于调试目的:
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: my-pipeline
spec:
tasks:
- name: test-repo-task
taskRef:
kind: Task
name: test-repo
- name: do-stuff
runAfter:
- test-repo-task
taskRef:
kind: Task
name: other-task
when:
- input: 'True'
operator: in
values:
- $(tasks.test-repo.results.passed)
- name: show-task-result
params:
- name: PS_COMMANDS
value: echo "$(tasks.test-repo-docs.results.passed)"
- name: PATH_CONTEXT
value: .
- name: POWERSHELL_IMAGE
value: mcr.microsoft.com/powershell:latest
runAfter:
- do-stuff
taskRef:
kind: ClusterTask
name: powershell
show-task-result
输出True
,但do-stuff
任务仍然每次都会跳过。我尝试将 when
条件更改为全部小写('true'),我还尝试将 PowerShell 脚本中输出的值从布尔值($true
)更改为字符串('true
') )但没有什么区别。
我还尝试交换
when
条件输入/值:
when:
- input: $(tasks.test-repo.results.passed)
operator: in
values:
- 'true'
我在这里做错了什么?
感谢文档中的 this note,我的结果输出附加了换行符,导致
when
测试失败。
为了解决这个问题,我使用了
-NoNewLine
的 Set-Content
参数:
steps:
- image: 'mcr.microsoft.com/powershell:latest'
name: repo-passed
script: |
#!/usr/bin/env pwsh
if (Run-Tests){
Set-Content -Path $(results.passed.path) -Value $true -Force -NoNewLine
}