Skip to content

Commit

Permalink
Don't overwrite BUILDKITE_METAHOOK_HOOKS_PATH
Browse files Browse the repository at this point in the history
If we have multiple `metahook` instances, let's not generate multiple
temporary directories; instead just create one (and only dump the
environment variables once).

This fixed an issue with multiple `metahook` instances in a pipeline of
mine.
  • Loading branch information
staticfloat committed Jun 14, 2021
1 parent 5fb4afe commit d3dc683
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions hooks/environment
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env bash
set -euo pipefail

BUILDKITE_METAHOOK_HOOKS_PATH="$(mktemp -d)"
export BUILDKITE_METAHOOK_HOOKS_PATH
env | sort | grep "BUILDKITE_PLUGIN_METAHOOK" | uniq >"${BUILDKITE_METAHOOK_HOOKS_PATH}/vars"
# If users add multiple `metahook` instances, we'll just store our `vars` in the same directory.
if [[ ! -v "BUILDKITE_METAHOOK_HOOKS_PATH" ]]; then
export BUILDKITE_METAHOOK_HOOKS_PATH="$(mktemp -d)"
env | sort | grep "BUILDKITE_PLUGIN_METAHOOK" | uniq >"${BUILDKITE_METAHOOK_HOOKS_PATH}/vars"
fi

if grep -E 'BUILDKITE_PLUGIN_METAHOOK_.+(\.BAT|\.CMD)=' "${BUILDKITE_METAHOOK_HOOKS_PATH}/vars"; then
echo "Sorry, we had to remove Windows Batch file support in 0.4.0."
Expand Down

0 comments on commit d3dc683

Please sign in to comment.