From bcc366633a39ff761238a48a8537b6cedfef1e8c Mon Sep 17 00:00:00 2001 From: Simon Baird Date: Fri, 2 Aug 2024 14:58:05 -0400 Subject: [PATCH] Use var for images file in rhtap task Short explanation: Clean up the code a little by using a variable. Long explanation: This task gets converted to a bash script and wrapped by a Jenkins shared library in the brand new RHTAP Jenkins pipeline sample templates. When testing the RHTAP Jenkins pipeline I found the default Jenkins user could not write to /tmp/, so I wanted to change the location of the file. This refactor makes that just a single line change, rather than having to change the path in three places. See also https://github.com/redhat-appstudio/tssc-sample-jenkins/pull/1/ where this PR was suggested by @mmorhun, and also https://github.com/jduimovich/tssc-jenkins/pull/2 where the cosign, Enterprise Contract, and promote pipeline support was being added to the RHTAP Jenkins templates. --- task/gather-deploy-images/0.1/gather-deploy-images.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/task/gather-deploy-images/0.1/gather-deploy-images.yaml b/task/gather-deploy-images/0.1/gather-deploy-images.yaml index 8d2b7cccc3..7ac989e15a 100644 --- a/task/gather-deploy-images/0.1/gather-deploy-images.yaml +++ b/task/gather-deploy-images/0.1/gather-deploy-images.yaml @@ -40,6 +40,7 @@ spec: set -euo pipefail IMAGE_PATH='.spec.template.spec.containers[0].image' + IMAGES_FILE='/tmp/all-images.txt' component_name=$(yq .metadata.name application.yaml) for env in "$@"; do @@ -55,9 +56,9 @@ spec: fi printf "%s\n" "$image" - done | sort -u > /tmp/all-images.txt + done | sort -u > $IMAGES_FILE - if [ ! -s /tmp/all-images.txt ]; then + if [ ! -s $IMAGES_FILE ]; then echo "No images to verify" touch $(results.IMAGES_TO_VERIFY.path) exit 0 @@ -66,7 +67,7 @@ spec: # TODO: each component needs a {"source": {"git": {"url": "...", "revision": "..."}}} # will that be too large for Tekton results? - jq --compact-output --raw-input --slurp < /tmp/all-images.txt ' + jq --compact-output --raw-input --slurp < $IMAGES_FILE ' # split input file split("\n") | # drop empty lines