Skip to content

Instantly share code, notes, and snippets.

@bobhenkel
Forked from toolmantim/pipeline.sh
Created September 4, 2018 13:55
Show Gist options
  • Save bobhenkel/4acf0c85ede0363dba6752926f260ef3 to your computer and use it in GitHub Desktop.
Save bobhenkel/4acf0c85ede0363dba6752926f260ef3 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