Skip to content

Instantly share code, notes, and snippets.

@toolmantim
Last active December 8, 2022 07:19
Show Gist options
  • Save toolmantim/1337952c8b5b1e5b0b5ea10c40e9efe4 to your computer and use it in GitHub Desktop.
Save toolmantim/1337952c8b5b1e5b0b5ea10c40e9efe4 to your computer and use it in GitHub Desktop.
Ensuring Buildkite pipeline steps run on the same agent, using a dynamic pipeline generator script
#!/bin/bash
# Outputs a pipeline that targets agents that have the same 'name' meta-data
# value as the step that does the pipeline upload. This means that all the
# steps will run on the same agent machine, assuming that the 'name' meta-data
# value is unique to each agent.
#
# Each agent needs to be configured with meta-data like so:
#
# meta-data="name=<unique-name>"
#
# To use, save this file as .buildkite/pipeline.sh, chmod +x, and then set your
# first pipeline step to run this and pipe it into pipeline upload:
#
# .buildkite/pipeline.sh | buildkite-agent pipeline upload
#
name=$(buildkite-agent meta-data get name)
cat << EOF
steps:
- command: step-1.sh
name: "First step"
agents:
name: "$name"
- command: step-2.sh
name: "Second step"
agents:
name: "$name"
- command: step-3.sh
name: "Third step"
agents:
name: "$name"
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment