35

I am trying to figure out if there is a difference between the two pre-defined variables in TFS Online 2017: $(Build.Repository.LocalPath) and $(Build.SourcesDirectory). I have a build that uses these two variables and didn't know if I could use them interchangeably or not.

Looking at Microsoft's documentation the descriptions are as follows:

$(Build.SourcesDirectory): The local path on the agent where your source code files are downloaded. For example: c:\agent_work\1\s By default, new build definitions update only the changed files. You can modify how files are downloaded on the Repository tab.

$(Build.Repository.LocalPath): The local path on the agent where your source code files are downloaded. For example: c:\agent_work\1\s By default, new build definitions update only the changed files. You can modify how files are downloaded on the Repository tab.

Are these representing the same thing or am I missing something?

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
JCisar
  • 2,584
  • 2
  • 29
  • 28

2 Answers2

25

They're synonyms. Most standard templates and tasks use the $(Build.SourcesDirectory), so that is what I tend to use.

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
4

They often result in the same but not necessarily. As described in the docs:

If you check out multiple repositories, the behavior is as follows (and might differ from the value of the Build.SourcesDirectory variable):

The description for Build.SourcesDirectory on the same page contains a similar note.

Basically if you want to define a custom path for the self checkout and still not need to specify the extra dir, you specifically need Build.Repository.LocalPath.

For clarity, you can still use Build.SourcesDirectory to resolve to the full path if you have the usual

- checkout: self
  path: s

and I'd recommend using it whenever possible if so. If you have something like

- checkout: self
  path: main_project

then you'd need $(Agent.BuildDirectory)/main_project to reach the same.

insideClaw
  • 323
  • 1
  • 8