0

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.

  • i think if you have a HDD space issue, nothing will work anyway ? – Thomas Sep 07 '21 at 08:22
  • Why? One build cannot take the whole HDD. Only when several builds in a row failed to clean up under themselves we have an issue. @danielorn's suggestion shall work. – Anton Merzliakov Sep 09 '21 at 08:37

1 Answers1

2

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.

danielorn
  • 5,254
  • 1
  • 18
  • 31