【发布时间】:2022-11-02 23:12:00
【问题描述】:
我尝试从 Azure DevOps YAML 管道运行以下 PowerShell 文件:
parameters:
- name: sub_name # name of the subscription; required
type: string
default: false
steps:
- script: echo "Here is subscription name:" ${{ parameters.sub_name }}
- task: AzurePowerShell@5
displayName: 'Launching Main.yml'
inputs:
azurePowerShellVersion: LatestVersion
azureSubscription: My-SPN # This is my allmighty Service Principle
ScriptType: 'FilePath'
ScriptPath: '$(System.DefaultWorkingDirectory)/MyPowerShell.ps1'
ScriptArguments: -sub_name ${{ parameters.sub_name }}
MyPowerShell.ps1 看起来像这样
$SID=(Get-AzSubscription -SubscriptionName $sub_name).id
这个错误说:
##[错误]在租户中找不到订阅 AzureSubcription1。请验证该租户中是否存在订阅。 ##[错误]PowerShell 以代码“1”退出。
但是,如果我将 $sub_name 指定为 PowerShell 中的变量,如下所示
$sub_name=AzureSubcription1
$SID=(Get-AzSubscription -SubscriptionName $sub_name).id
它工作正常,没有任何错误。
在命令的文档中它说:
-SubscriptionId <System.String>
Specifies the ID of the subscription to get.
Required? false
Position? named
Default value None
Accept pipeline input? True (ByPropertyName)
Accept wildcard characters? false
我究竟做错了什么?
我尝试在我的笔记本电脑上使用 PowerShell 5 运行它,它运行良好。 我尝试使用 Out-String -InputObject $sub_name 没有帮助。
【问题讨论】:
标签: azure yaml devops azure-powershell azure-pipelines-yaml