# Creating a step that runs after everything else

**URL:** <https://forum.buildkite.community/t/creating-a-step-that-runs-after-everything-else/4410>\
**Category:** Pipelines\
**Created:** [June 18, 2025, 1:42pm UTC](https://forum.buildkite.community/t/creating-a-step-that-runs-after-everything-else/4410 "2025-06-18T13:42:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zenogueira](https://avatars.discourse-cdn.com/v4/letter/z/e480ec/32.png) [@zenogueira](https://forum.buildkite.community/u/zenogueira)\
**Post date:** [June 18, 2025, 1:42pm UTC](https://forum.buildkite.community/t/creating-a-step-that-runs-after-everything-else/4410/1 "2025-06-18T13:42:21Z")

</div>

Hello,

we have a dynamically generated pipeline that runs a few apps deployments in phases (let’s say deploy, config, start) that depend on each other. Eg: apps A, B and C each have all these phases.

I want to add a step at the end of the build to cleanup some leftover files, but I need to wait for these steps to come to completion before doing it. In the same manner, if they fail, I want to run this cleanup step too.

AFAIU, if I add these deployments’ steps as dependencies, even if I accept failures, my cleanup step won’t run because the dependent steps never run if their dependencies fail. EG: I can depend on deploy, config, start, but start may never run, or I can depend on start and have the same issue.

Is there a way to say: when this build is considered finished (succeeded, failed, canceled, whatever), just run another step?

---

<div class="post-metadata">

**Author:** ![lukasz-buildkite](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/lukasz-buildkite/32/1590_2.png) [@lukasz-buildkite](https://forum.buildkite.community/u/lukasz-buildkite)\
**Post date:** [June 18, 2025, 2:27pm UTC](https://forum.buildkite.community/t/creating-a-step-that-runs-after-everything-else/4410/2 "2025-06-18T14:27:54Z")

</div>

Hey @zenogueira 👋

Reading through your post I think [wait step](https://buildkite.com/docs/pipelines/configure/step-types/wait-step) might be easiest way to achieve that — running cleanup at the end of the pipeline, regardless result of previous steps.

Sample pipeline:

```auto
steps:
  - label: "Generate and upload pipeline"
    command: |
      cat << 'EOF' | buildkite-agent pipeline upload
      steps:
      - key: "deploy-a"
        command: "echo deploy app A"

      - key: "config-a" 
        command: "echo config app A && exit 1"
        depends_on: "deploy-a"

      - key: "start-a"
        command: "echo start app A" 
        depends_on: "config-a"

      - wait: ~
        continue_on_failure: true

      - key: "cleanup"
        command: "echo cleanup files"
      EOF

```

This is how it’d look like in canvas steps view:

 ![Screenshot 2025-06-18 at 16.16.43](https://us1.discourse-cdn.com/flex016/uploads/buildkite1/original/2X/a/a0ae948e9b624f4a71a88174eb3d354c14144441.png)

Hope that helps!

---

<div class="post-metadata">

**Author:** ![zenogueira](https://avatars.discourse-cdn.com/v4/letter/z/e480ec/32.png) [@zenogueira](https://forum.buildkite.community/u/zenogueira)\
**Post date:** [June 18, 2025, 3:58pm UTC](https://forum.buildkite.community/t/creating-a-step-that-runs-after-everything-else/4410/3 "2025-06-18T15:58:56Z")

</div>

Hey Lukasz,

I think that’s exactly what I need.

Thanks a lot.

---

<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:** [July 19, 2025, 1:59am UTC](https://forum.buildkite.community/t/creating-a-step-that-runs-after-everything-else/4410/4 "2025-07-19T01:59:26Z")

</div>

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