Skip to content

Instantly share code, notes, and snippets.

@toolmantim
Last active August 3, 2017 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toolmantim/43de11658602b3f7c0e1921fcea7ac5f to your computer and use it in GitHub Desktop.
Save toolmantim/43de11658602b3f7c0e1921fcea7ac5f to your computer and use it in GitHub Desktop.
An example custom Buildkite bootstrap wrapper for optimizing git fetch with Phabricator builds

To test this bootstrap wrapper:

git clone https://gist.github.com/43de11658602b3f7c0e1921fcea7ac5f.git optimized-phabricator-bootstrap

cd optimized-phabricator-bootstrap

docker run \
  --rm \
  -it \
  -v "$(pwd)/custom-bootstrap:/buildkite/custom-bootstrap" \
  -e BUILDKITE_BOOTSTRAP_SCRIPT_PATH=/buildkite/custom-bootstrap \
  -e BUILDKITE_AGENT_TOKEN=xxx \
  buildkite/agent:3 start

Run a build for the branch refs/heads/master, and in the "Preparing build directory" section you should see:

# Fetch and checkout custom refspec
git fetch -v origin refs/heads/master
#!/bin/bash
# A custom bootstrap wrapper that sets the BUILDKITE_REFSPEC to avoid the
# agent fetching all the tags
#
# To use this file, either set the env variable before starting the agent:
# BUILDKITE_BOOTSTRAP_SCRIPT_PATH=/path-to-this-file
#
# or the agent configuration key:
# bootstrap-script=/path-to-this-file
echo "~~~ :git: Optimize git fetch refspec for Phabricator"
# Optimize the git fetching of SHA1 from Phabricator
# https://github.com/buildkite/agent/issues/504
export BUILDKITE_REFSPEC="$BUILDKITE_BRANCH"
exec buildkite-agent bootstrap "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment