Skip to content

Commit a7bf57e

Browse files
authored
fix: resolve subshell issue in image validation loop (#15)
## Problem The image validation was failing with exit code 1 even when all validation checks passed successfully. This was caused by a bash subshell issue. ## Root Cause The validation loop used a pipe pattern: ```bash echo "$NEW_IMAGES" | jq -r '.[]' | while IFS= read -r image; do # validation code that writes to /tmp/validation_failed.txt done ``` This pattern creates a subshell, and files written inside the subshell (`/tmp/validation_failed.txt`) are not visible to the parent shell after the loop completes. ## Solution Changed to process substitution pattern: ```bash while IFS= read -r image; do # validation code that writes to /tmp/validation_failed.txt done < <(echo "$NEW_IMAGES" | jq -r '.[]') ``` This runs the loop in the current shell context, allowing file writes to persist correctly. ## Testing This fix will be validated with test PR #360 in deutschebank-infrastructure repository, which previously showed all checks passing but failed with exit code 1. ## Related - Fixes validation failure in dotCMS/deutschebank-infrastructure#360
1 parent eda022f commit a7bf57e

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

.github/workflows/deployment-guard.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,8 @@ jobs:
393393
mapfile -t OLD_IMAGES_ARRAY < <(echo "$OLD_IMAGES" | jq -r '.[]')
394394
395395
INDEX=0
396-
echo "$NEW_IMAGES" | jq -r '.[]' | while IFS= read -r image; do
396+
# Use process substitution to avoid subshell issues with pipe
397+
while IFS= read -r image; do
397398
echo "=================================================="
398399
echo "Validating image: $image"
399400
echo "=================================================="
@@ -540,7 +541,7 @@ jobs:
540541
541542
echo "✅ Image validated successfully: $image"
542543
echo ""
543-
done
544+
done < <(echo "$NEW_IMAGES" | jq -r '.[]')
544545
545546
if [ -f /tmp/validation_failed.txt ]; then
546547
echo "result=fail" >> "$GITHUB_OUTPUT"

0 commit comments

Comments
 (0)