I am using elastic CI stack for AWS for my buildkite agents, where I am using a boostrap script that runs on my agents before my buildkite steps are executed. Is there any way I can implement some logic within the bash script such that the relevant buildkite steps that use the agent will not fail the build (either passing or skipping the step is fine), and will not execute the commands given in the pipeline.yml files? Something like using exit 1 in the bootstrap script will not work as this will cause the build to outright fail in buildkite.
Hey @georgeji19951995,
Welcome to the community!
There are a few ways to skip a step in Buildkite, though I see you’re interested in using the bootstrap script. However, since the bootstrap script (which only includes agent variables) runs before any hooks or custom environment variables, it may not be ideal for skipping steps based on conditions.
Instead, you could use a command hook to exit the step with a 0
status, egardless of the step’s command outcome:
bash
hooks/command
set -e
exit 0
Alternatively, in your pipeline YAML, you can set conditions directly on steps to control when they run.
yaml
steps:
- label: "Test"
command: test.sh
branches: "main"
Or:
For instance, you can specify that a step only runs on a certain branch or use the skip
attribute to bypass the step altogether:
yaml
steps:
- label: "Test"
command: test.sh
skip: true
For more on conditionals, check out Buildkite’s docs on conditional steps.
Thanks @stephanie.atte .
Unfortunately I don’t believe these suggestions will work for me - I would like to decide to skip certain steps from within the bootstrap script (for my use case I can’t edit the steps in the .yml file directly) based on certain agent variables. From your first paragraph this seems to be possible - would you mind showing me how I can do this?
Hey @georgeji19951995,
Unfortunately, this isn’t possible directly from the bootstrap script. When the bootstrap script runs, the job/build setup hasn’t yet been configured to run commands. However, you can achieve this through the pipeline configuration or by using a command hook to make the step exit with a 0 status, regardless of the actual command outcome.