8
votes

Just to mention I am using a self-hosted agent for running my build and release pipelines.

The problem is when I run any build and it failed due to some issues in the pipeline. The cloned branch from remote sits in the _work directory. The second run also picks up the same work directory, and I have checked manually from the agent _work directory no new directory was cloned and I can also verify from Azure Pipeline logs they are using the same old directory.

What I did temporarily to solve this, I went into the old directory(i.e. /home/user/_work/13) and manually delete that 13 directories then azure pick it up the new folder say 14 under _work, and I could see the latest cloned code from the remote.

So how to automatically delete the work folder(agent build directory i.e. 13/14 under _work) in case of any failure happen.

PS: I already have cleanup steps in place when my pipeline complete with success, which I run at the end. Also, I am writing .yml based pipelines.

Please let me know if any information is required for a better understanding.

1
Are you using Git or TFVC? Are you using YAML pipelines or classic pipelines? Did you look at the documentation for working folder cleaning options? - Daniel Mann
I am using the azure git repository, I am not getting why someone down voted this, if they found it silly why do not they answer it .. - Indrajeet Gour
I down voted because you left out significant amounts of relevant information that is necessary to help you. You still haven't provided it. - Daniel Mann
@DanielMann, let me know if anything else you required for better understanding. thank you - Indrajeet Gour

1 Answers

21
votes

Azure DevOps - Clean build directory

There is an Clean option on the Get Source tab, which could perform different kinds of cleaning of the working directory of your private agent before the build is run:

enter image description here

We could set the value to true to clean the working directory of your private agent. Even if the build is failed.

You could check the document Clean the local repo on the agent for some more details.

Update:

But this is meant for the classic pipeline, do not we have any tag which we define in yml pipeline only

jobs:
- job: string  # name of the job (A-Z, a-z, 0-9, and underscore)
  ...
  workspace:
    clean: outputs | resources | all # what to clean up before the job runs

Check this document YAML schema reference for some details. Hope this helps.