В Azure Devops у меня есть конвейер YAML, который выполняет задачу Powershell, которая:
- Появляется для вызова моего сценария, но в журналы не выводятся выходные данные, и
- Задача заканчивается с ошибкой,
Could not find a part of the path 'C:\Users\VssAdministrator\Documents\WindowsPowerShell\profile.ps1'.
Как мне:
- заставить PS вывести результаты в журналы конвейера и
- устранить ошибку в конце задачи
Шаг:
- task: AzurePowerShell@4
displayName: 'Azure PowerShell script: SetAzureFirewallRule'
inputs:
azureSubscription: '***'
ScriptPath: SetAzureFirewallRule.ps1
ScriptArguments: '-ServerName {myserver} -ResourceGroup {myrg} -AzureFirewallName {rulename}'
azurePowerShellVersion: LatestVersion
Файл сценария прост:
[CmdletBinding(DefaultParameterSetName = 'None')]
param
(
[String] [Parameter(Mandatory = $true)] $ServerName,
[String] [Parameter(Mandatory = $true)] $ResourceGroup,
[String] $AzureFirewallName = "AzureWebAppFirewall"
)
Enable-AzureRmAlias -Scope CurrentUser
$agentIP = (New-Object net.webclient).downloadstring("http://checkip.dyndns.com") -replace "[^\d\.]"
echo "IP is $($agentIP)"
New-AzureRmSqlServerFirewallRule -ResourceGroupName $ResourceGroup -ServerName $ServerName -FirewallRuleName $AzureFirewallName -StartIPAddress $agentIp -EndIPAddress $agentIp
Примечание. Мне пришлось отклониться от сценария , рекомендованного Microsoft , добавив Enable-AzureRmAlias -Scope CurrentUser
. Этот сценарий работает, как и ожидалось, при выполнении с моей машины разработки, включая отображение вывода.
Когда он выполняется, регистрируется следующее:
##[section]Starting: Azure PowerShell script: SetAzureFirewallRule
==============================================================================
Task : Azure PowerShell
Description : Run a PowerShell script within an Azure environment
Version : 4.159.3
Author : Microsoft Corporation
Help : [Learn more about this task](https://go.microsoft.com/fwlink/?LinkID=613749)
==============================================================================
##[command]Import-Module -Name C:\Modules\az_2.6.0\Az.Accounts\1.6.2\Az.Accounts.psd1 -Global
##[command]Clear-AzContext -Scope Process
##[command]Clear-AzContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue
##[command]Connect-AzAccount -ServicePrincipal -Tenant *** -Credential System.Management.Automation.PSCredential -Environment AzureCloud
##[command] Set-AzContext -SubscriptionId *** -TenantId ***
##[command]& 'd:\a\1\s\SetAzureFirewallRule.ps1' -ServerName *** -ResourceGroup *** -AzureFirewallName ***
##[command]Disconnect-AzAccount -Scope Process -ErrorAction Stop
##[command]Clear-AzContext -Scope Process -ErrorAction Stop
##[error]Could not find a part of the path 'C:\Users\VssAdministrator\Documents\WindowsPowerShell\profile.ps1'.
##[section]Finishing: Azure PowerShell script: SetAzureFirewallRule
Я пробовал это сразные хосты:
- windows-latest
- windows-2019
- vs2017-win2016
с одинаковыми результатами.