【发布时间】:2021-08-17 16:36:12
【问题描述】:
我正在创建一个部署管道,它将包作为 Python 包部署到 Pypi 或 Docker 容器。我想通过处理 workspace 的内容并将判断("Python" 或 "Docker")传递给 when 块来确保调用正确的部署 Task下游任务。
问题是,当我将结果传递给 when 块时,它与值不匹配,即使我认为它应该匹配,就像我将结果记录到创建它的任务中一样,甚至将它分配给参数并将其记录在具有预期内容的下游任务中。
没有when 块的管道执行没有问题。
系统信息:
$ tkn version
Client version: 0.15.0
Pipeline version: v0.24.1
Triggers version: v0.8.1
$ k version --short
Client Version: v1.19.0
Server Version: v1.19.0+b00ba52
管道中的相关任务:
- name: check-appropriate-build-task
taskRef:
kind: Task
name: check-build-type
workspaces:
- name: source
workspace: shared-workspace
runAfter:
- fetch-repository
- name: build-and-upload-python-package
params:
- name: TWINE_REPOSITORY_URL
value: $(params.twine-url)
when:
- input: $(tasks.check-appropriate-build-task.results.build-type)
operator: in
values:
- "Python"
taskRef:
kind: Task
name: upload-pypi
workspaces:
- name: source
workspace: shared-workspace
runAfter:
- check-appropriate-build-task
check-build-type 任务:
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: check-build-type
spec:
results:
- name: build-type
workspaces:
- name: source
steps:
- name: check-build-type
image: alpine
script: |
if test -f "$(workspaces.source.path)/setup.cfg"; then
if grep -q Python "$(workspaces.source.path)/setup.cfg"; then
echo "Python" > $(results.build-type.path)
fi
elif test -f "$(workspaces.source.path)/Dockerfile"; then
echo "Docker" > $(results.build-type.path)
fi
cat $(results.build-type.path)
提前致谢。
【问题讨论】:
-
理论上看起来不错。也许有'\ n'的东西?你试过
echo -n Python吗? -
是的,我最终也明白了,你是对的。随意回答这个问题,这样我就可以投票并接受奖励积分;)
标签: conditional-statements pipeline tekton