Anton  Merzliakov
Anton Merzliakov

Reputation: 85

Azure DevOps: Run step after pipeline failed

Sometimes our builds fail. If that happens, then the workspace is not cleaned. New builds just create new workspaces, which eats up all HDD space.

Is there a way to clean the workspace after the build has failed?

Right now I have a clean-up step with a condition succeedOrFailed(), but it works only if the build was cancelled manually. If the build has failed due to a lack of HDD space or because of the timeout -- the clean-up step is not run.

I don't actually need to clean up. If the TFS-agent would just reuse old workspace directories it would have been a fine solution since I have clean:all in my YAML. But for some reason it prefers to create new ones.

I guess I can run rm -rf in cron, but then I would need to know when nobody uses the build system.

Upvotes: 2

Views: 4085

Answers (1)

danielorn
danielorn

Reputation: 6147

Specify the condition as always(). It will run the cleanup regardless of whether the pipeline failed/succeded or was canceled. This ways the workspace will always clean, also after successful builds, minimizing the risk of getting out of space on the agent

From the docs

Even if a previous dependency has failed, unless the run was canceled. Use succeededOrFailed() in the YAML for this condition.

Even if a previous dependency has failed, even if the run was canceled. Use always() in the YAML for this condition.

Only when a previous dependency has failed. Use failed() in the YAML for this condition.

Upvotes: 3

Related Questions