Friday, June 16, 2017

WORSKPACE: delete or not delete?!





If you are reading my blog, probably you understand, that my blog is about cheating using usual feature and fixing bug from Microsoft.



Today I want speaking about workspace.
Few words for people, who don't know why need workspace, and how does their work.
First of all a worksapce is record (row) in tfs database. When you create build, you put path, which need download and than work with their. Usually we build code.
But, if we open script, which in first order download source, which you setup in build, we find next workflow:

  1. Create workspace:
    1. Create row in database. If you have permission, you will see this workspace anywhere.
    2. Map folder in build agent with this workspace.
  2. Download source code to map folder.
  3. If build failed, you can build it without download it again.

There are two problems.
1) If you have inheritance OFF for root of TFVC, and you set variable build.clean=source during build, you will noticed, that their try synchronize workspace, but nothing downloading.
2) If you have inheritance ON in root of TFVC, every this synchronize and clean. But after few years you will find than there are tons of workspace. The question is: why we need save workspace for build, which was deleted many times ago? Decide should every body by himself: delete id every time, or scope workspace every X years.

I provide for you some cheat how few issue, which I describe.

  1. Add to build step: Command Line.
  2. In Tool: tf.exe (Should in build agent before put to windows path folder where placed tf.exe and visual studio)
  3. In Arguments: workspace /delete "$(Build.Repository.Tfvc.Workspace);Build\$(System.CollectionId)"
  4. Enable: Always run.
  5. This step should be last in workspace.
After that your worksapce will remove after each build. I tested this approach, and it works perfect!

Happy build!

No comments:

Post a Comment