Ah gotcha. To reiterate:
You would like to run a job on a particular agent but only if the agent is available. If the agent is not available you just want the pipeline to continue.
To do that you can use dynamic pipelines.
Here’s how it would work:
- You run a script that checks for the availability of the device (e.g. with ping) or the agent (via the Agents API)
- The outcome of the script determines the next pipeline step
To ensure that the job runs on a specific agent you can use Agent targeting.
I ran a test to see if it works. Here’s what I did:
I have a niktest.yml in my .buildkite folder
I have a script.sh in my src folder
I started an agent with hostname “swarm-1-1” and a tag so that I can target it with:
buildkite-agent start --tags "queue=special"
Following the dynamic pipelines doc I put the following in niktest.yml:
- command: src/script.sh | buildkite-agent pipeline upload
- command: echo "Final step in YAML file"
label: ":smile: Done!"
This is the content of script.sh:
# Note that we don't enable the 'e' option, which would cause the script to
# immediately exit if it fails
set -uo pipefail
# Query all agents and set the SUB string to the desired agent hostname
STR=$(curl -H "Authorization: Bearer $TOKEN" https://api.buildkite.com/v2/organizations/niks-playground/agents)
read -r -d '' VAR << EOM
- command: echo "It worked!"
# begin the pipeline.yml file
# add a new command step based on agent availability
if [[ "$STR" == *"$SUB"* ]]; then
echo " - command: echo \"Skipped\""
VAR contains the steps that are injected into the pipeline if the agent is available.
This is what I got when the agent was not running:
This is what I got when it was:
That should do it, right?