Depends_on with conditional

Hey @UnknownTester404 :wave:

Seems like this might be related to your other question here?

There are a few ways you could do this,

Here’s one example:

#!/bin/bash

set -euo pipefail

FOO=BAR

cat << EOF | buildkite-agent pipeline upload
    steps:
        - label: "hello world"
          command: echo "Hello World"
          key: ${FOO}
        - label: "second command"
          command: echo "a second command is run"
          depends_on:
           - "${FOO}"
EOF

In the above example, I’ve declared FOO in my script, and then generated my pipeline steps in a heredoc, referencing FOO to set the key in the uploaded pipeline yaml.

Another way would be to directly reference the variables in your pipeline YAML:

steps:
        - label: "hello world"
          command: echo "Hello World"
          key: $FOO
        - label: "second command"
          command: echo "a second command is run"
          depends_on:
           - $FOO

There are some caveats to referencing your environment variables directly in the pipeline yaml like this - which are outlined in our docs. The short version of the doc I linked is:

As long as you have declared the value of FOO in the job environment before the pipeline upload is called, the pipeline yaml should be parsed correctly.

Hope that helps!