VSO中目标机器上的电源外壳

时间:2017-12-13 09:52:54

标签: azure-devops azure-pipelines

'目标机器上的电源外壳' VSO中的步骤仅在步骤完成后显示日志。在此步骤运行时,有什么方法可以看到日志吗? 无论我写了什么' Write-verbose'注释仅在步骤完成后显示。

1 个答案:

答案 0 :(得分:0)

使用内置的 PowerShell on target machine 任务,您无法在远程脚本运行时获取日志。

源代码:

  $deploymentResponse = Invoke-Command -ScriptBlock $RunPowershellJob -ArgumentList $machine, $scriptPath, $resourceProperties.winrmPort, $scriptArguments, $initializationScriptPath, $resourceProperties.credential, $resourceProperties.protocolOption, $resourceProperties.skipCACheckOption, $enableDetailedLoggingString, $sessionVariables, $PSScriptRoot 
    Write-ResponseLogs -operationName $deploymentOperation -fqdn $displayName -deploymentResponse $deploymentResponse 

####################################################

$job = Start-Job -ScriptBlock $RunPowershellJob -ArgumentList $machine, $scriptPath, $resourceProperties.winrmPort, $scriptArguments, $initializationScriptPath, $resourceProperties.credential, $resourceProperties.protocolOption, $resourceProperties.skipCACheckOption, $enableDetailedLoggingString, $sessionVariables, $PSScriptRoot 
$Jobs.Add($job.Id, $resourceProperties) 
...
Write-ResponseLogs -operationName $deploymentOperation -fqdn $displayName -deploymentResponse $output

解决方法是您可以通过 PowerShell 任务调用Invoke-Command:

$p=ConvertTo-SecureString "password" -AsPlainText -Force
$mc=New-Object System.Management.Automation.PSCredential("username",$p)
Invoke-Command -ComputerName [machine] -FilePath "hello.ps1" -Credential $mc