I am using a self-hosted agent for running my build and release pipelines.
A problem happens after I run a build and it fails due to an issue in the pipeline. The cloned branch from remote sits in the working directory. The second run also uses the same working directory, not a new one. I have verified on the agent that no new directory was created. I can also see in the Azure Pipeline logs that it's using the same old directory.
What I did temporarily to solve this was I located the old working directory (e.g. /home/user/_work/13) and manually deleted it. Then Azure creates a new folder (e.g. "14") under _work, and I could see the latest cloned code from the remote in that new directory.
How can I automatically delete the working folder (the numbered directory under _work) when a failure occurs?
Note: I already have put clean-up steps in place at the end of my pipeline which run when the pipeline completes with success. Also, I am writing YAML pipelines, not Classic.
Please let me know if any information is required for a better understanding.