通过在VS Team Services构建中运行的Powershell创建工作区 [英] Create a workspace from Powershell run within VS Team Services build
问题描述
我正在将Powershell脚本编写为Visual Studio Team Services构建的一部分,该构建使用托管的构建控制器.该脚本旨在检出文件,进行更改然后将其检回.
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.
在脚本中,我试图调用tf
命令来创建新的工作区,但是遇到身份验证问题.命令
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/
产生错误:
TF30063:您无权访问 https://mycollection.visualstudio.com/.
如何在不将登录名或密码嵌入脚本的情况下从Powershell脚本访问TFS?我可以在本身登录到TFS的构建代理的上下文中访问TFS吗?还是我应该采取另一种方式?
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?
请注意,我没有使用TFS Power Tool cmdlet,因为它是托管的构建服务器.似乎也没有使用TFS RestAPI的选择,因为没有工具可以签入或签出文件.
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.
推荐答案
- 选中允许脚本访问您的构建定义的OAuth令牌"选项
- 将/noprompt/loginType:OAuth/login:.,$(System.AccessToken)附加到TF命令(参数)
- Check Allow Scripts to Access OAuth Token option of your build defition
- Append /noprompt /loginType:OAuth /login:.,$(System.AccessToken) to your TF command (arguments)
关于TF命令,您可以查看此文章.
About TF Command, you can check this article.
这篇关于通过在VS Team Services构建中运行的Powershell创建工作区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!