apiVersion: tekton.dev/v1alpha1 kind: Task metadata: name: check-git-files-changed annotations: description: | Returns "passed" in the "check" result if any of the files changed in the source on the workspace matches the regular expression. Returns a "files" result as a list of files modified by the PR that match the regex in the parameters. ci.tekton.dev/condition: | The result of this task is used to evaluate a condition. Events from this task are ignored downstream, when it comes to update the CI job status. spec: params: - name: gitCloneDepth description: Number of commits + 1 - name: regex description: Regular expression to match files changed workspaces: - name: input results: - name: check description: passed or failed - name: files description: list of files modified that match steps: - name: check-files-changed image: alpine/git env: - name: GIT_CLONE_DEPTH value: $(params.gitCloneDepth) - name: REGEX value: $(params.regex) script: | #!/bin/sh set -ex set -o pipefail BACK="HEAD~$(( ${GIT_CLONE_DEPTH} - 1 ))" CHECK="failed" cd $(workspaces.input.path) git diff-tree --no-commit-id --name-only -r HEAD $BACK | \ grep -E "${REGEX}" > $(results.files.path) || true git diff-tree --no-commit-id --name-only -r HEAD $BACK | \ grep -E "${REGEX}" && CHECK="passed" printf $CHECK > $(results.check.path)