I created a very simple task that checks if the current branch on a git repo is a release branch
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: check-git-remote-release-branches
spec:
params:
- default: .
description: The location of the root folder
name: PATH_CONTEXT
type: string
- default: master
description: Git reference
name: GIT_REF
type: string
results:
- description: true if release branch
name: is-release-branch
steps:
- image: 'registry.redhat.io/rhel8/nodejs-16:latest'
name: retrieving-remote-release-branches
resources: {}
script: >
#!/bin/bash
set -x
git config --global --add safe.directory '*'
git config --global user.email "git@48hg.ch"
git config --global user.name "48hG - CICD"
REMOTE_RELEASE_BRANCHES=($(git ls-remote --heads origin | grep release/
| awk '{print $2}'))
echo "Current ref $(params.GIT_REF)"
echo REMOTE_RELEASE_BRANCHES
echo "false" | tee $(results.is-release-branch.path)
for element in "${REMOTE_RELEASE_BRANCHES[@]}"; do
echo "$element"
if [[ $element == $(params.GIT_REF) ]]; then
echo "true" | tee $(results.is-release-branch.path)
fi
done
cat $(results.is-release-branch.path)
workingDir: /workspace/source/$(params.PATH_CONTEXT)
workspaces:
- name: source
In my Tekton pipeline i setup a task that writes on a "result" true if the branch is a release branch.
- name: check-git-remote-release-branches
params:
- name: PATH_CONTEXT
value: $(params.context_path)
- name: GIT_REF
value: $(params.git-ref)
runAfter:
- continuous-integration-nodejs
taskRef:
kind: Task
name: check-git-remote-release-branches
workspaces:
- name: source
workspace: source-workspace
A subsequent task uses this result to evaluate a when clause:
- name: release-increase-version
params:
- name: PATH_CONTEXT
value: $(params.context_path)
runAfter:
- check-git-remote-release-branches
taskRef:
kind: Task
name: nodejs-release-commit
when:
- input: $(tasks.check-git-remote-release-branches.results.is-release-branch)
operator: in
values:
- 'true'
the when clause does never work even if true is wrote in the right file. How can i debug this? is there a way for me to check why the comparison fails?
I suspect the issue is related to how the result is produced:
echo "true" | tee $(results.is-release-branch.path)
Using echo
will produce true\n
as a result, which does not match the when
expression.
I would recommend changing the task definition to:
printf "true" | tee $(results.is-release-branch.path)