【问题标题】:VSTS Remote Powershell task throwing errorVSTS Remote Powershell 任务抛出错误
【发布时间】:2019-02-13 07:09:44
【问题描述】:

我正在 VSTS 中创建一个构建定义,它将构建 Windows 服务并将 Windows 服务部署到特定服务器。

我能够将所有必需的 Windows 服务文件复制到服务器中。我正在使用 powershell 脚本来安装和启动这些 Windows 服务。我的服务器中已经有 powershell 脚本。我的最后一个 VSTS 任务远程 Powershell 任务正在抛出以下内容

[错误]连接到远程服务器失败并显示以下错误消息:WinRM 无法完成操作。验证指定的计算机名称是否有效,该计算机可通过网络访问,并且 WinRM 服务的防火墙例外已启用并允许从该计算机进行访问。默认情况下,公共配置文件的 WinRM 防火墙例外限制对同一本地子网中的远程计算机的访问。有关详细信息,请参阅 about_Remote_Troubleshooting 帮助主题。

Powershel 脚本代码:

$serviceName = "Service"
$displayName = "Service name"            
$sourceLocation = "C:\temp\Service\bin\Release\*"
$destinationLocation = "C:\TestService\"
$binaryName = $destinationLocation + "Service1.exe"
$serviceName = "Service1"
$serviceDef = Get-Service -Name $serviceName -ErrorAction SilentlyContinue

If ($serviceDef -eq $null)
{
   New-Item $destinationLocation -ItemType directory 
   Copy-Item $sourceLocation $destinationLocation -Force
   New-Service -Name $serviceName -StartupType Automatic -DisplayName $displayName -BinaryPathName $binaryName
}
else
{
  # has already been installed
  if($serviceDef.Status -eq "Running")
  {
    Stop-Service -Name $serviceName        
  }
  Copy-Item $sourceLocation $destinationLocation -Force
}
Start-Service -Name $serviceName


$serviceName = "Service2"
$displayName = "Service2"            
$sourceLocation = "C:\temp\Service2\bin\Release\*"
$destinationLocation = "C:\Service2\"
$binaryName = $destinationLocation + "Service2.exe"
$serviceName = "Service2"
$serviceDef = Get-Service -Name $serviceName -ErrorAction SilentlyContinue

If ($serviceDef -eq $null)
{
   New-Item $destinationLocation -ItemType directory 
   Copy-Item $sourceLocation $destinationLocation -Force
   New-Service -Name $serviceName -StartupType Automatic -DisplayName $displayName -BinaryPathName $binaryName
}
else
{
  # has already been installed
  if($serviceDef.Status -eq "Running")
  {
    Stop-Service -Name $serviceName        
  }
  Copy-Item $sourceLocation $destinationLocation -Force
}
Start-Service -Name $serviceName

【问题讨论】:

  • 您是否在目标计算机上启用了 Windows 远程处理(Enable-PSRemoting 或 winrm quickconfig)?
  • 这不是脚本的问题。这是 WinRM / PowerShell 远程处理的问题。
  • 您是否使用托管代理来运行构建?可以从公共互联网访问远程机器吗?
  • 我正在使用自托管代理。我 ping 了我试图从构建服务器运行 poweshell 脚本的服务器,即我托管构建代理的服务器
  • ping 成功

标签: windows powershell azure-devops powershell-remoting azure-pipelines-build-task


【解决方案1】:

根据错误信息,应该是 WinRM 问题,您需要在特定服务器上启用 WinRM。

只需尝试在特定服务器上以管理员身份从 cmd 运行命令 winrm quickconfig 以启用 WinRM。之后再试一次。

 C:\Windows\system32>WinRM quickconfig
 WinRM service is already running on this machine.
 WinRM is not set up to allow remote access to this machine for management.
 The following changes must be made:

 Create a WinRM listener on HTTP://* to accept WS-Man requests to any IP on this
 machine.

 Make these changes [y/n]? y

 WinRM has been updated for remote management.

 Created a WinRM listener on HTTP://* to accept WS-Man requests to any IP on this
 machine.

【讨论】:

  • 我试过这个命令,它说“WinRM 服务已经在这台机器上运行”,“WinRM 已经在这台电脑上设置了远程管理。”
  • 每当我尝试运行构建定义时,我注意到的一件事是 VSTS RemotePowershell 任务在端口 5986 上运行,所以您认为这可能是问题所在?
  • 除了在 VM 的防火墙上添加例外,如果您在 Azure 中托管,请转到“网络”设置并在那里添加防火墙例外。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-10-25
  • 1970-01-01
  • 2015-11-06
  • 2018-12-10
  • 1970-01-01
  • 2015-06-10
  • 1970-01-01
相关资源
最近更新 更多