Skip to content

Instantly share code, notes, and snippets.

@flokli
Created February 18, 2020 15:40
Show Gist options
  • Save flokli/d6895f3722a8ec88696e218f282473bd to your computer and use it in GitHub Desktop.
Save flokli/d6895f3722a8ec88696e218f282473bd to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# buildkite groups the builds by BUILDKITE_BRANCH.
# This allows us to arbitrarily group buildkite jobs, while still allowing
# agents to checkout, if change and revision id is passed in metadata.
set -euo pipefail
if buildkite-agent meta-data exists change_id && buildkite-agent meta-data exists revision_id; then
change_id="$(buildkite-agent meta-data get change_id)"
revision_id="$(buildkite-agent meta-data get revision_id)"
partial_change_id="${change_id: -2:2}"
# refs/changes/%s/%s/%s", changeID[len(changeID)-2:], changeID, revisionID)
export BUILDKITE_BRANCH="refs/changes/${partial_change_id}/${change_id}/${revision_id}"
echo "switched BUILDKITE_BRANCH to ${BUILDKITE_BRANCH}"
else
echo "using BUILDKITE_BRANCH ${BUILDKITE_BRANCH}"
fi
exec buildkite-agent bootstrap "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment