# Conditional trigger skip if previous step failed

**URL:** <https://forum.buildkite.community/t/conditional-trigger-skip-if-previous-step-failed/2060>\
**Category:** General\
**Created:** [May 27, 2022, 5:45am UTC](https://forum.buildkite.community/t/conditional-trigger-skip-if-previous-step-failed/2060 "2022-05-27T05:45:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joe](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/joe/32/1080_2.png) [@Joe](https://forum.buildkite.community/u/Joe)\
**Post date:** [May 27, 2022, 5:45am UTC](https://forum.buildkite.community/t/conditional-trigger-skip-if-previous-step-failed/2060/1 "2022-05-27T05:45:47Z")

</div>

I want to trigger another pipeline at the end of the main CI build. However, I want to trigger it to only run or skip based on the previous step build status?

---

<div class="post-metadata">

**Author:** ![paula](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/paula/32/954_2.png) [@paula](https://forum.buildkite.community/u/paula)\
**Post date:** [May 27, 2022, 5:49am UTC](https://forum.buildkite.community/t/conditional-trigger-skip-if-previous-step-failed/2060/2 "2022-05-27T05:49:26Z")

</div>

Hey @Joe looks like you need something like this: [buildkite-agent step v3 | Buildkite Documentation](https://buildkite.com/docs/agent/v3/cli-step#getting-the-outcome-of-a-step)

If you combine that with a dynamic pipeline upload and possibly with [Managing step dependencies | Buildkite Documentation](https://buildkite.com/docs/pipelines/dependencies#allowing-dependency-failures) you should have everything you need to achieve such a pipeline structure.

---

<div class="post-metadata">

**Author:** ![Joe](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/joe/32/1080_2.png) [@Joe](https://forum.buildkite.community/u/Joe)\
**Post date:** [May 27, 2022, 6:23am UTC](https://forum.buildkite.community/t/conditional-trigger-skip-if-previous-step-failed/2060/4 "2022-05-27T06:23:39Z")

</div>

The skip below the trigger command, how to make it conditional?

```auto
#!/bin/bash

set -euo pipefail

result="$(buildkite-agent step get outcome --step filter1)"

buildkite-agent pipeline upload <<YAML
steps:
  - label: "The pr pipeline"
    trigger: "pr-pipeline"
    skip: if [$(buildkite-agent step get "outcome" --step "filter2") == "soft_failed"]; then
        "skip"
      fi
    build:
      env:
        RESULT: "${result}"
YAML

```

---

<div class="post-metadata">

**Author:** ![paula](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/paula/32/954_2.png) [@paula](https://forum.buildkite.community/u/paula)\
**Post date:** [May 27, 2022, 6:37am UTC](https://forum.buildkite.community/t/conditional-trigger-skip-if-previous-step-failed/2060/5 "2022-05-27T06:37:29Z")

</div>

Good question.

It depends if you still want it in the pipeline but marked as skipped. Otherwise you could just not upload it. The `skip` attribute only takes a boolean, and it can’t be evaluated like you’re example above.

I would do something like this and avoid the `skip` attribute entirely:

```bash
if [$(buildkite-agent step get "outcome" --step "one") == "soft_failed"]; then
  buildkite-agent pipeline upload ...
fi

```

This would only upload the step if you want to run it, and not upload it if you don’t. Otherwise, you could do something similar to set the `skip` attribute true/false.
