# Conditioning a step on the EXIT\_CODE of the previous step

**URL:** <https://forum.buildkite.community/t/conditioning-a-step-on-the-exit-code-of-the-previous-step/1036>\
**Category:** General\
**Created:** [May 13, 2020, 3:11am UTC](https://forum.buildkite.community/t/conditioning-a-step-on-the-exit-code-of-the-previous-step/1036 "2020-05-13T03:11:21Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![jaganiku](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@jaganiku](https://forum.buildkite.community/u/jaganiku)\
**Post date:** [May 13, 2020, 3:11am UTC](https://forum.buildkite.community/t/conditioning-a-step-on-the-exit-code-of-the-previous-step/1036/1 "2020-05-13T03:11:21Z")

</div>

I want to achieve the following:

```
steps:
  - label: "failing step"
    command: exit -1

  - wait

  - label: "run ONLY if previous step has non-zero exit status"
    command: echo "PREV STEP FAILED"
    if: (prev_step_exit_code != 0) # how do i change this here?

```

The idea is to conditionally run a step based on the exit status of the previous step, but i’m not exactly sure if this is the right way to do it. Is this possible?

---

_[View the full topic](https://forum.buildkite.community/t/conditioning-a-step-on-the-exit-code-of-the-previous-step/1036)._
