Creating a step that runs after everything else

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?

Hey @zenogueira :waving_hand:

Reading through your post I think wait step might be easiest way to achieve that — running cleanup at the end of the pipeline, regardless result of previous steps.

Sample pipeline:

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:

Hope that helps!

Hey Lukasz,

I think that’s exactly what I need.

Thanks a lot.

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