# Depends\_on with conditional

**URL:** <https://forum.buildkite.community/t/depends-on-with-conditional/3871>\
**Category:** Pipelines\
**Created:** [August 14, 2024, 10:53am UTC](https://forum.buildkite.community/t/depends-on-with-conditional/3871 "2024-08-14T10:53:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![UnknownTester404](https://avatars.discourse-cdn.com/v4/letter/u/f04885/32.png) [@UnknownTester404](https://forum.buildkite.community/u/UnknownTester404)\
**Post date:** [August 14, 2024, 10:53am UTC](https://forum.buildkite.community/t/depends-on-with-conditional/3871/1 "2024-08-14T10:53:37Z")

</div>

Hello,

I have a steps with depends\_on: keyName

But I want to have the keyName on depends\_on based on variable which I am setting when starting the job.

For example I would want for a mobile platform to have depends\_on: download and if the platform is web to be depends\_on: install.

The logic will be used on a running test step which would have this depends\_on dynamic.

THanks

---

<div class="post-metadata">

**Author:** ![jeremy](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/jeremy/32/1040_2.png) [@jeremy](https://forum.buildkite.community/u/jeremy)\
**Post date:** [August 14, 2024, 5:33pm UTC](https://forum.buildkite.community/t/depends-on-with-conditional/3871/2 "2024-08-14T17:33:40Z")

</div>

Hey @UnknownTester404 👋

Seems like this might be related to your other question [here](https://forum.buildkite.community/t/buildkite-with-input-steps-and-schedules/3859/6)?

There are a few ways you could do this,

Here’s one example:

```sh
#!/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](https://linuxize.com/post/bash-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:

```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](https://buildkite.com/docs/pipelines/environment-variables#environment-variable-precedence). 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!

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/system/32/1321_2.png) [@system](https://forum.buildkite.community/u/system)\
**Post date:** [September 14, 2024, 3:34am UTC](https://forum.buildkite.community/t/depends-on-with-conditional/3871/3 "2024-09-14T03:34:22Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
