2

Normally, if you are using a self-hosted Azure agent, it automatically selects target folders for you (I assume based on pipeline name), underneath the work folder... so for example:

/home/xxxxx/azure/_work/2/t/

Is there a way that I can control this choice from a YAML pipeline? My use case is that I have a very large repo, and several different pipelines that all check it out. I only have one agent running on the machine, so my preference is that all of the pipelines I run on this agent check out into the same folder (like /home/xxxxx/azure/_work/MyProject), ensuring that there will only be one checkout of this large repo.

Elliot Nelson
  • 11,371
  • 3
  • 30
  • 44
  • 1
    Have you considered doing shallow checkouts to reduce the cloned repo size? – Daniel Mann Apr 27 '21 at 16:07
  • @DanielMann This is a good idea, I might use in some other contexts. My preference in this case is still to use one folder if I can, because there are a bunch of other dependencies and cacheable assets that can be reused if I don't check out fresh. – Elliot Nelson Apr 27 '21 at 16:51

2 Answers2

1

You could avoid syncing sources at all in the pipeline by setting checkout: none:

steps:
- checkout: none

Then add a command line or script task to clone the repo manually via git commands.

Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39
  • Thanks Cece - I don't know if that helps. I can clone the repo manually, but the value of `pwd` will still potentially one of many random folders (`1/s`, `2/t`, etc.). I guess I could add a script step that does `mkdir -p ../../myWorkFolder && cd ../../myWorkFolder`, but my concern is that this will break any tasks like collect coverage & publish artifacts that assume my files are in a normal work folder. – Elliot Nelson Apr 28 '21 at 17:18
  • You could set source folder for these tasks. – Cece Dong - MSFT Apr 29 '21 at 06:08
  • OK -- so one option is to just work "outside the _work folder", in a place of my choosing, and just do things manually. Makes sense! – Elliot Nelson Apr 29 '21 at 11:17
0

We've recently been testing linking the source folder and it has been working pretty well, so that is possibly an easier answer than the accepted one.

That is, you can create a specific folder (let's say ~/projects/Acme or C:\projects\acme), and then in your Azure pipeline steps before checkout you delete the s folder and link it to the target project folder.

# In PowerShell (Windows)
New-Item -Type Junction -Path s -Target C:\projects\acme

# In Bash (Linux/MacOS)
ln -s ~/projects/acme s

The advantage to this approach is that you don't have to attempt to override the working folder for dozens of builtin tasks scattered throughout your pipelines and template files; it's a bit of setup at the top of the pipeline and then the rest of the tasks can operate as normal.

Elliot Nelson
  • 11,371
  • 3
  • 30
  • 44