Create a workspace from Powershell run within VS Team Services build

余生长醉 提交于 2020-01-02 04:02:14

问题


I am writing a Powershell script as part of a Visual Studio Team Services build, this build uses a hosted build controller. The script is intended to check out a file, make changes then check it back in.

In the script I am trying to invoke the tf command to create a new workspace but I'm having authentication issues. The command

& $tf vc workspace /new $tempWorkspaceName /collection:https://mycollection.visualstudio.com/ 

produces the error:

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

How can I access TFS from my Powershell script without embedding logins or passwords in the script? Can I access TFS within the context of the build agent, which itself logs in to TFS? Or is there another way I should be doing this?

Note that I haven't used the TFS Power Tool cmdlets as it is a hosted build server. Using the TFS RestAPI also doesn't appear to be an option as there is no facility to check a file in or out.


回答1:


  1. Check Allow Scripts to Access OAuth Token option of your build defition
  2. Append /noprompt /loginType:OAuth /login:.,$(System.AccessToken) to your TF command (arguments)

About TF Command, you can check this article.



来源:https://stackoverflow.com/questions/40732535/create-a-workspace-from-powershell-run-within-vs-team-services-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!