I am creating a deployment pipeline that would deploy packages as either Python packages to Pypi or Docker containers. I want to ensure correct deployment Task is called by processing contents of a workspace and passing the verdict (either "Python"
or "Docker"
) to a when
block in downstream tasks.
The problem is that when I pass the result to a when
block it does not match the values even though I believe it should, as when I log the result in the task that creates it, or even assign it to a parameter and log it in downstream tasks it has the expected contents.
Pipeline without the when
block executes no problem.
System information:
$ 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
Relevant tasks in pipeline:
- 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 task:
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)
Thanks in advance.
It appears that check is failing due to a trailing \n
.
We can fix the check-build-type Task, replacing echo
with echo -n
.