Skip to content

Commit 38b582a

Browse files
committed
Adjust how packer validate is called
Break out the `packer validate` call so we can: - Disable errexit for _just_ the `packer validate` call so every path has an attempt at validation. - Get the output of the `packer validate` call so that if there is a non-zero exit code we can output that along with the path being validated.
1 parent e1e8cd7 commit 38b582a

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

hooks/packer_validate.sh

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,25 @@ set -o nounset
44
set -o errexit
55
set -o pipefail
66

7+
function packer_validate() {
8+
local exit_code=0
9+
10+
packer init . > /dev/null
11+
12+
# Allow us to get output if the validation fails
13+
set +o errexit
14+
validate_output=$(packer validate "${ARGS[@]}" . 2>&1)
15+
exit_code=$?
16+
set -o errexit
17+
18+
if [[ $exit_code -ne 0 ]]; then
19+
echo "Validation failed in $path"
20+
echo -e "$validate_output\n\n"
21+
fi
22+
23+
return $exit_code
24+
}
25+
726
if [ -z "$(command -v packer)" ]; then
827
echo "packer is required"
928
exit 1
@@ -24,8 +43,7 @@ for path in "${UNIQUE_PATHS[@]}"; do
2443
# Check each path in parallel
2544
{
2645
pushd "$path" > /dev/null
27-
packer init . > /dev/null
28-
packer validate "${ARGS[@]}" .
46+
packer_validate
2947
} &
3048
pids+=("$!")
3149
done

0 commit comments

Comments
 (0)