# How can I depends\_on the possible missing steps?

**URL:** <https://forum.buildkite.community/t/how-can-i-depends-on-the-possible-missing-steps/2209>\
**Category:** Pipelines\
**Created:** [September 6, 2022, 1:19pm UTC](https://forum.buildkite.community/t/how-can-i-depends-on-the-possible-missing-steps/2209 "2022-09-06T13:19:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![haohaolee](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/haohaolee/32/1115_2.png) [@haohaolee](https://forum.buildkite.community/u/haohaolee)\
**Post date:** [September 6, 2022, 1:19pm UTC](https://forum.buildkite.community/t/how-can-i-depends-on-the-possible-missing-steps/2209/1 "2022-09-06T13:19:55Z")

</div>

Hi folks, I am now using monorepo-diff plugins to trigger both frontend and backend changes at the same time. But I have another step which depends on some steps in frontend and backend, which may lead to build failure because sometimes only frontend or backend are triggered, and the dependent step does not exist at all. It is like the following example:

```auto
steps:
  - label: "Triggering pipelines"
    plugins:
      - chronotc/monorepo-diff#v2.3.0:
          diff: "git diff --name-only HEAD~1"
          watch:
            - path: "frontend/"
              config:
                command: "buildkite-agent pipeline upload frontend.yml"
            - path: "backend/"
              config:
                command: "buildkite-agent pipeline upload backend.yml"
 - label: "some step"
    depends_on:
    - some_key_in_frontend_yml
    - some_key_in_backend_yml
   command: "echo hello"

```

I am not using `wait: true` here, because I don’t want to wait for all the steps in backend and frontend to finish.  
What I want is when some steps to depend on are missing, the dependent step does not fail.

_I have read the docs and I know that for such a case, the result is failure_

Any suggestion is appreciated~ Maybe I am in the wrong direction for this task.

Thanks

---

<div class="post-metadata">

**Author:** ![animatedgif](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/animatedgif/32/1121_2.png) [@animatedgif](https://forum.buildkite.community/u/animatedgif)\
**Post date:** [September 6, 2022, 3:04pm UTC](https://forum.buildkite.community/t/how-can-i-depends-on-the-possible-missing-steps/2209/2 "2022-09-06T15:04:12Z")

</div>

I struggled with this myself and the only way I could get it to work was way more hacky than I would have liked & expected.

I resorted to manually modifying the pipeline.yml file before upload

```auto
# .buildkite/hooks/post-checkout
export JS_FILES_CHANGED_COUNT=$(git --no-pager diff master... --name-only --diff-filter=d -- ./\*\*\*.js ./\*\*\*.jsx ./\*\*\*.ts ./\*\*\*.tsx ./\*\*\*.json ./\*\*\*.graphql ./\*\*\*.snap | sort | uniq | wc -l | awk '{print $1}')

sed_option="-i"
if [["$OSTYPE" == "darwin"*]]; then
  sed_option="-i ''"
fi

if ["$JS_FILES_CHANGED_COUNT" == "0"]; then
  sed $sed_option "s/\(- step: .* # if JS_FILES_CHANGED_COUNT\)/# \1/g" ".buildkite/pipeline.yml"
fi

```

Then in pipeline.yml, annotate the depends\_on with the “magic comment”

```auto
    depends_on:
      - step: jest # if JS_FILES_CHANGED_COUNT

```

Really annoying to have to do all this, but I hope it helps.

Hopefully in the future buildkite will add an option for this instead.

---

<div class="post-metadata">

**Author:** ![animatedgif](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/animatedgif/32/1121_2.png) [@animatedgif](https://forum.buildkite.community/u/animatedgif)\
**Post date:** [September 6, 2022, 3:09pm UTC](https://forum.buildkite.community/t/how-can-i-depends-on-the-possible-missing-steps/2209/3 "2022-09-06T15:09:05Z")

</div>

FTR my jest step looks like this:

```auto
  - label: "Jest"
    key: jest
    if: |
      (
        (build.message !~ /skip.?(jest)/ && "${JS_FILES_CHANGED_COUNT}" != "0") ||
        build.branch =~ /^(master|deploy\/production|deploy\/staging|deploy\/sandbox)\$/
      )

```

---

<div class="post-metadata">

**Author:** ![haohaolee](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/haohaolee/32/1115_2.png) [@haohaolee](https://forum.buildkite.community/u/haohaolee)\
**Post date:** [September 6, 2022, 3:36pm UTC](https://forum.buildkite.community/t/how-can-i-depends-on-the-possible-missing-steps/2209/4 "2022-09-06T15:36:02Z")

</div>

Thank you for your hacky solution.

Inspired by you, I think maybe another way is to fork or contribute monorepo-diff, and add a when-not-match command to execute some command when there is no diff. So we can add a dummy step with id we want to satisfy the `depends_on`. Still ugly…

---

<div class="post-metadata">

**Author:** ![animatedgif](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/animatedgif/32/1121_2.png) [@animatedgif](https://forum.buildkite.community/u/animatedgif)\
**Post date:** [September 6, 2022, 3:43pm UTC](https://forum.buildkite.community/t/how-can-i-depends-on-the-possible-missing-steps/2209/5 "2022-09-06T15:43:38Z")

</div>

Yeah this whole issue seems very solvable natively, because buildkite already has soft-fail and depends\_on configuration, such as `allow_failure: true`. To me it seems like it should be easy to add `allow_skipped: true` or something similar.

> <https://github.com/buildkite/docs/pull/879/files#diff-cf05558a9adee10d47e7c7e3c4da29898cfbac30d4c07d107b7a6b95a8fcf034R149-R151>
>
> This is half a fix for #840 
> 
> It doesn't systematically document all the state…s, but does clarify the specific issue.
