sduplooy
sduplooy

Reputation: 14720

Determine if workspace exists on build server

Is it possible to determine whether a workspace exist on the server given the local path using tf.exe?

This can be done using the TFS API but that would require me to build the task source code before using it which is not possible because I don't have a workspace yet. Checking binaries into source control is not an option.

Any ideas?

Upvotes: 2

Views: 2271

Answers (1)

Robaticus
Robaticus

Reputation: 23157

If you run the tf.exe workfold command passing in the local directory, it will either return an error if the folder is not mapped, or it will return the workspace information. You can (in a hacky fashion) determine if an error occurred by redirecting the stderr to a text file, then checking to see if the file is empty. For example:

tf.exe workfold c:\some\mapping\folder\path 2> error.txt

You may also be able to check the exit code from the command. Based on research, it looks like the exit code is set to 100 if there's an error. Not sure what you can do in the task, but in a CMD file you can check ERRORLEVEL.

To see this in action, try:

tf.exe workfold "C:\program files" 2> error.txt
echo %ERRORLEVEL%

Upvotes: 4

Related Questions