Depends_on with conditional

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

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!

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