# Conditional logic in bootstrap script to not fail buildkite step without running further commands

**URL:** <https://forum.buildkite.community/t/conditional-logic-in-bootstrap-script-to-not-fail-buildkite-step-without-running-further-commands/4021>\
**Category:** Elastic CI Stack for AWS\
**Created:** [November 4, 2024, 3:59pm UTC](https://forum.buildkite.community/t/conditional-logic-in-bootstrap-script-to-not-fail-buildkite-step-without-running-further-commands/4021 "2024-11-04T15:59:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![georgeji19951995](https://avatars.discourse-cdn.com/v4/letter/g/5daacb/32.png) [@georgeji19951995](https://forum.buildkite.community/u/georgeji19951995)\
**Post date:** [November 4, 2024, 3:59pm UTC](https://forum.buildkite.community/t/conditional-logic-in-bootstrap-script-to-not-fail-buildkite-step-without-running-further-commands/4021/1 "2024-11-04T15:59:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stephanie.atte](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/stephanie.atte/32/1357_2.png) [@stephanie.atte](https://forum.buildkite.community/u/stephanie.atte)\
**Post date:** [November 4, 2024, 9:27pm UTC](https://forum.buildkite.community/t/conditional-logic-in-bootstrap-script-to-not-fail-buildkite-step-without-running-further-commands/4021/2 "2024-11-04T21:27:22Z")

</div>

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

```auto
set -e
exit 0

```

Alternatively, in your pipeline YAML, you can set conditions directly on steps to control when they run.

yaml

```auto
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

```auto
steps:
  - label: "Test"
    command: test.sh
    skip: true

```

For more on conditionals, check out Buildkite’s [docs on conditional steps](https://buildkite.com/docs/pipelines/conditionals#conditionals-in-steps).

---

<div class="post-metadata">

**Author:** ![georgeji19951995](https://avatars.discourse-cdn.com/v4/letter/g/5daacb/32.png) [@georgeji19951995](https://forum.buildkite.community/u/georgeji19951995)\
**Post date:** [November 4, 2024, 11:02pm UTC](https://forum.buildkite.community/t/conditional-logic-in-bootstrap-script-to-not-fail-buildkite-step-without-running-further-commands/4021/3 "2024-11-04T23:02:15Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![stephanie.atte](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/stephanie.atte/32/1357_2.png) [@stephanie.atte](https://forum.buildkite.community/u/stephanie.atte)\
**Post date:** [November 4, 2024, 11:34pm UTC](https://forum.buildkite.community/t/conditional-logic-in-bootstrap-script-to-not-fail-buildkite-step-without-running-further-commands/4021/4 "2024-11-04T23:34:36Z")

</div>

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.
