How to stop / exit from step

Hello Team,

I have script to check the files(list of file changes from each commit) in each step. When specific file not updated then I have to stop the build with note and build should not be mark as failure. Is there any best way do that. I have added exit 0 but build does not stop. Can some one recommend ?

For below example,

I have validatespconfig powershell script having logic to check the specific file and executed exit 0 but build continue to execute next command.

  • label: “export”
    commands:
    - pwsh .buildkite/scripts/validatespconfig.ps1
    • buildkite-agent artifact upload ./exportedfile.json
      key: “Export”
      if: “build.branch == ‘main’”
  • wait
  • label: “import”
    commands:
    - pwsh .buildkite/scripts/validatespconfig.ps1
    • pwsh .buildkite/scripts/importSPConfig.ps1
      key: “Import”
      if: “build.branch == ‘main’”
      depends_on: “Export”
      allow_dependency_failure: true

@paula - When you have time, Can you please take a look ?

hey @sukurams good question.

Exiting 0 is a success result so that is why the build continues past the step. But if you want the build to still succeed but not continue you will still need to exit 0.

I think the only option here is to have the first step that does the “check files” also upload the other steps if successful. Builds can upload more steps at any time so if step 1 executed and if the file is updated, then it can upload more steps and allow the build to continue on with new steps. However, if you required file is not present it would not upload more steps. It will still exit 0 to mark the build as successful, but it wont be able to run other steps that dont exist

Its similar to this in the docs that we call “dynamic pipelines” Defining Your Pipeline Steps | Buildkite Documentation. Where one step uploads more steps based on some logic within the step itself