2

I'm trying to run a powershell script as a build step for TFS2015. In the script I have tf history /r /noprompt /loginType:OAuth /login:.,$env:SYSTEM_ACCESSTOKEN, as I saw in this answer, but I get the following error: TF10120: The value OAuth is not supported for option loginType.

Moreover, I don't see any documentation for the /logintype option. Was it deprecated / not supported in Visual studio 2015?

What can I do to call tf commands from my script with proper authorization?

liorda
  • 1,552
  • 2
  • 15
  • 38

2 Answers2

1

This is not documented anywhere, you could find related info after enable system.debug=true in a build definition, then check the build log for TF command related. For example, in the get source task, there should be something like:

tf vc workspaces /format:xml /collection:https://tfs.MyCompany.net/tfs/Collection/ /loginType:OAuth /login:.,******** /noprompt

According to your error message, seems the built-in tf.exe does not supports OAuth on your build agent.

As a workaround you could use the /login:username,password: If you want to run the command as another user, you must specify the /login option verbatim, replace username with the name of the user, and if necessary, you can supply the password.

Details please refer this thread: Use /login option to specify credentials when running a command

PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62
1

In the current version of VSTS I was experiencing the same symptons when using this PowerShell script - $AccessToken is passed as $(System.AccessToken).

Param(
  [string]$AccessToken
)

if (Test-Path -Path "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\TF.exe") { "TF.exe Exists" }

$TFFile = Get-Item "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\TF.exe"

Write-Host [string](& $TFFile.FullName vc workspaces /collection:*<collection name>* /loginType:OAuth /login:.,$AccessToken)

However, when I used Name (TF.exe) instead of FullName in the script I was able to get it to work. The following script is working

Param(
  [string]$AccessToken
)

if (Test-Path -Path "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\TF.exe") { "TF.exe Exists" }

$TFFile = Get-Item "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\TF.exe"

Write-Host [string](& $TFFile.Name vc workspaces /collection:*<collection name>* /loginType:OAuth /login:.,$AccessToken)

The other difference I have with your original command line was the addition of the vc part. This I mimicked from the commands that are run when the code is pulled from source control (Get Sources)

IsolatedStorage
  • 1,175
  • 12
  • 12
  • Yeah, I believe tf.exe version 14.* does not support /logintype. In your case it's working probably because you have tf.exe version 15+ installed and available from path. – liorda Nov 02 '17 at 18:10