Scott Langham
Scott Langham

Reputation: 60441

How do I authenticate with TFVC from a release-pipeline task?

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.

Upvotes: 4

Views: 765

Answers (1)

Shayki Abramczyk
Shayki Abramczyk

Reputation: 41775

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

Upvotes: 4

Related Questions