TFS 代理在文件夹中没有权限

TFS agent have no permissions in a folder

我有一个 PowerShell 脚本,它需要访问文件夹并在其中创建内容(例如删除或重命名子文件夹)。我认为它崩溃是因为我的本地 TFS 代理被拒绝访问此远程计算机中的此文件夹。错误信息是:

2017-10-12T12:49:06.6816226Z ##[error]Remove-Item : Cannot remove item \[path_to_the_folder_I_want_my_script_to_access]\old.1: Access to the path

2017-10-12T12:49:06.6835446Z ##[error]is denied.

我用谷歌搜索了这个问题并找到了一个可能的解决方案:将脚本访问的文件夹的 read/write 权限授予我的 TFS 的构建服务帐户(Svc_tfsbuild 帐户)。但它不起作用。

因此,如果有人有其他解决方案,那就太棒了。 :D

在此先感谢您。

祝你有愉快的一天!


是权限问题,请确保您已正确设置权限,让 Build Agent 服务帐户可以访问该文件夹。

你说的是“the code did work with another agent, a TFS test agent”,所以你可以对比Build Agent服务账号和test agent服务账号来更正权限设置。

另一种解决方法是 运行 删除项目命令 具有特定凭据 ,它具有删除 folder/files 的足够权限。如果该帐户在本地工作,那么它在构建过程中也将工作。我在身边测试和工作。

您可以使用以下示例脚本来执行此操作:

Param(
  [string]$computerName = "vtinmo502vm",
  [string]$path ="C:\Software\test.txt"
)
$Username = "domain\user"
$Password = ConvertTo-SecureString "EnterPasswordHere" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($Username,$password) 
Invoke-Command -computername $computerName {Remove-Item -path $args[0] -Recurse} -cred $cred  -ArgumentList $path