【问题标题】:Invoking batch script with specific user from TFS build server从 TFS 构建服务器调用具有特定用户的批处理脚本
【发布时间】:2017-05-29 01:37:44
【问题描述】:

我是 TFS 新手,需要帮助来解决以下问题。

我有一个桌面,它有一个许可的测试工具和使用该工具开发的自动化测试。该工具的许可证与登录到该桌面的用户相关联。 现在我为我的自动化测试创建了一个批处理文件,我想从 TFS 调用这个批处理文件。我已经在该工具所在的桌面上安装了 TFS 代理,并且在 TFS 服务器上配置了一个运行此批处理文件的构建定义,到目前为止一切正常。

问题是,当 TFS 代理(我认为)调用批处理脚本时,它作为 SYSTEM 用户参与,而不是与许可证绑定的用户。因此,许可证检查失败,我的测试无法运行。 有没有办法告诉 TFS 使用特定用户运行批处理脚本?

【问题讨论】:

    标签: tfs tfsbuild


    【解决方案1】:

    批处理脚本使用构建服务帐户运行。如果要使用特定帐户运行批处理脚本,则需要更改构建代理服务帐户。

    对于 TFS 2015 Build 代理,运行命令:

    C:\Agent\Agent\VsoAgent.exe /ChangeWindowsServiceAccount
    

    请参考此文档更改账号:https://www.visualstudio.com/en-us/docs/build/actions/agents/v1-windows

    如果您使用 TFS 2017 Build 代理,只需 re-configure 它并在重新配置时指定该帐户。

    【讨论】:

    • 如果代理被多个项目使用,切换代理的身份不是个好主意。
    【解决方案2】:

    您可以使用 PowerShell 包装脚本来启动具有不同身份的可执行文件。

    param (
    
        [Parameter(Mandatory=$True)]
        [string]$username,
        [Parameter(Mandatory=$True)]
        [string]$password,
        [Parameter(Mandatory=$True)]
        [string]$executable,
        [Parameter(Mandatory=$False)]
        [string[]]$arguments,
        [Parameter(Mandatory=$False)]
        [string]$workingDirectory
    )
    
    
    $secpassword = $password | ConvertTo-SecureString -asPlainText -Force
    $password = $null
    $credentials = New-Object System.Management.Automation.PSCredential($username,$secPassword)
    
    $workingDirectory = if([string]::IsNullOrEmpty($workingDirectory)){(Get-Item -Path ".\").FullName}
    
    Start-Process $executable -ArgumentList $arguments -WorkingDirectory $workingDirectory -Credential ($credentials)
    

    在您的构建或发布定义中使用密码创建一个隐藏变量“密码”,并将可见性设置为隐藏。

    使用 powershell 步骤调用此脚本:

    -username "username" -password = $(password) -executable "myExecutable" -arguments '-param "param1"','-param2 "param2"','-param3"d:\directory\with blanks in a path\"'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-09
      • 2017-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-25
      相关资源
      最近更新 更多