Search code examples
batch-filetfsbuildtfsbuild

Get build agent folder path in tfs build


How to access TFS build agent folder path in using batchfile?

enter image description here

I am calling runscript tool from build workflow (calling windows batchfile). I tried to use the environment variable BUILD_REPOSITORY_LOCALPATH ($(BUILD_REPOSITORY_LOCALPATH), $env:BUILD_REPOSITORY_LOCALPATH) but they dint give any result. Need some assistance on this.


Solution

  • I used another workaround for this instead of getting by workspace. From sourceDirectory folder i drill down to find my solution project file, the path containing my solution project is the local directory path i need

    From batchfile i call my exe and pass %TF_BUILD_SOURCESDIRECTORY% as parameter.

    string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory) 
    // targetdirectory would be the input parameter from batch file`
    
    for (int i = 0; i < subdirectoryEntries.Length ; i++)
    {
         // My root folder always contains a specific folder with name MyFolder 
         // and a file Myfile.sln
    
         if (subdirectoryEntries[i].ToString().ToLower().Contains(@"MyFolder")) 
         {
              Console.Writeline("My source code path is " + targetDirectory);
         }   
    
         //Similarly I check for Myfile.sln and then get my path.             
    }
    

    This may be a very crude way, this worked for me.