4

I have a release pipeline and want to add a stage with a task that will write a version number into a file that is stored in TFVC.

I have been attempting to use a powershell task that calls tf.exe to work with files. I thought I'd start just by trying to download the file before considering attempting to check it back in. I can't seem to authorize using tf.exe to download a file. Can you help?

    $workspaceName = "temp_123"

    $login = "/login:.,$env:SYSTEM_ACCESSTOKEN"

    & tf vc workspace /new /noprompt $workspaceName /collection:https://mycorp.visualstudio.com $login
    Try
    {
        & tf vc workfold /unmap "$/" /workspace:$workspaceName $login
        & tf vc workfold /map "$/SomePath" $dir /workspace:$workspaceName $login
        & tf vc get $login
    }
    Finally
    {
        & tf vc workspace /delete $workspaceName /collection:https://mycorp.visualstudio.com $login
    }

        # Verify it appeared
    if (-Not (Test-Path "$dir\Version.txt")) { throw "failed to download" }

I get this error:

TF30063: You are not authorized to access https://mycorp.visualstudio.com/

How do you authenticate with tf.exe when you have a system access token? Or is there a better way to download and checkin files.

Scott Langham
  • 58,735
  • 39
  • 131
  • 204

1 Answers1

4

To authenticate from Azure DevOps from tf.exe you need to add /loginType:OAuth to the command.

For example:

tf vc workspace /new /noprompt $workspaceName /collection:https://mycorp.visualstudio.com /loginType:OAuth /login:.,[OAuth token]

In addition, there is the Check-in changes task in TFVC Build Tasks extension that you can use it to check in changes without problems.

enter image description here

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
  • I think I tried the /loginType:OAuth but if I recall, there was an error about /loginType not being an accepted command line parameter. When I googled that the solution was to get the latest version of tf.exe, but I determined I'm on the latest version. – Scott Langham Feb 10 '19 at 22:25
  • I guess for the TFVC tasks to work I need to have a workspace first? In a build-pipeline that creates one for you I guess that might work, but I'm in a release-pipeline. Also, there doesn't seem to be a TFVC task to pend an edit to an existing file, only to add new or delete files. – Scott Langham Feb 10 '19 at 22:26
  • @ScottLangham I didn't use the tasks in release pipeline, but it worth the check... the "Add" task is not only to add new files, it also for existing files, the task just add the changes to "pending changes". – Shayki Abramczyk Feb 11 '19 at 05:54