Skip to content

Commit

Permalink
Improve buildkite error reporting
Browse files Browse the repository at this point in the history
This will make it _much_ easier to pinpoint where that error annotation
is coming from.
  • Loading branch information
staticfloat committed Jun 24, 2024
1 parent e77bb61 commit 98f4e95
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions lib/buildkite_support.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,31 @@ else
die "No sha256sum/shasum available!"
fi

# Helper function to kill execution when something goes wrong
function die() {
echo "ERROR: ${1}" >&2
function job_link() {
echo -n "${BUILDKITE_BUILD_URL}#${BUILDKITE_JOB_ID}"
}

function buildkite_annotation() {
if which buildkite-agent >/dev/null 2>/dev/null; then
# By default, the annotation context is unique to the message
local CONTEXT=$(echo "${1}" | ${SHASUM})
if [[ "$#" -gt 1 ]]; then
CONTEXT="${2}"
# By default, the annotation context is unique to the message and buildkite job
local CONTEXT=$(echo "${2}" "${BUILDKITE_JOB_ID}" | ${SHASUM})
if [[ "$#" -gt 2 ]]; then
CONTEXT="${3}"
fi
buildkite-agent annotate --context="${CONTEXT}" --style=error "${1}"
buildkite-agent annotate --context="${CONTEXT}" --style="${1}" "${2} ([job]($(job_link)))"
fi
}

# Helper function to kill execution when something goes wrong
function die() {
echo "ERROR: ${1}" >&2
buildkite_annotation "error" "$@"
exit 1
}

function warn() {
echo "WARN: ${1}" >&2
if which buildkite-agent >/dev/null 2>/dev/null; then
# By default, the annotation context is unique to the message
local CONTEXT=$(echo "${1}" | ${SHASUM})
if [[ "$#" -gt 1 ]]; then
CONTEXT="${2}"
fi
buildkite-agent annotate --context="${CONTEXT}" --style=warning "${1}"
fi
buildkite_annotation "warning" "$@"
}

# Helper function to collect a buildkite array
Expand Down

0 comments on commit 98f4e95

Please sign in to comment.