Condition on triggered build success

We trigger another pipeline at the end of the main CI build. However, we’d like for certain steps to only run if the original/main build was successful. Is there a way to do this check in the if: key?

Hi @ngan! Hrmm good question.

Without an example pipeline, it might be a bit tricky to know what makes most sense for you, but I’ll outline a few things that might help.

For example, this could be the parent pipeline’s pipeline.yml file:

  - label: "🔨 Tests" 
    key: tests
  - label: ":pipeline:" 
    command: scripts/
    depends_on: tests
    allow_dependency_failure: true

The scripts/ script has the logic to upload an additional trigger step, with the env variable set for the child build, and the trigger step will be added immediately to the current build:


set -euo pipefail

test_step_outcome="$(buildkite-agent step get outcome --step tests)"

buildkite-agent pipeline upload <<YAML
  - label: "🚀 Child"
    trigger: "child-pipeline"
        TESTS_OUTCOME: "${test_step_outcome}"

And then in the child pipeline’s pipeline.yml, you can use an if conditional like so:

  - command:
    if: 'build.env("TESTS_OUTCOME") == "passed"'

The different step outcomes that you can check for are:

  • passed
  • hard_failed
  • soft_failed
  • neutral (e.g. wait steps, skipped steps)
  • errored (e.g. canceled, timed out, etc)

Would something like that solve what you’re trying to do? If not, perhaps let us know a little more about the context and pipeline, and we provide some more alternatives.