我正在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
答案 0 :(得分:0)
根据错误消息,应该是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.