【发布时间】:2020-09-08 16:33:19
【问题描述】:
我有一个带有多个参数的 Azure DevOps 管道来创建 VM
task: AzurePowerShell@5
inputs:
azureSubscription: 'Visual Studio Enterprise Subscription – MPN(07f41212-2053-434e-XXXX)'
ScriptType: 'FilePath'
ScriptPath: '$(System.DefaultWorkingDirectory)/CreateNewVMforImage.ps1'
ScriptArguments: -azSubscriptionId "07f41212-2053-434e-XXXXX" -azResourceGroupName "AZREUSMGMTRG" -azSnapshotName "SNAPSHOT2GOOD" -azNewOSDiskName "ImageOSDisk5" -azVMLocation "eastus" -azVMNetwork "MGMTVNET" -azVMName "AZREUSLSIMG6"
azurePowerShellVersion: LatestVersion
pwsh: true
如果我添加以下两个参数值,则管道执行错误输出,并且我理解这是由于下划线而发生的,因为其他值中没有任何下划线并且没有问题。只有当值在下面有下划线时,它才会在管道执行时给出错误。
-azVMStorageType "Standard_LRS"
-azVMSize "Standard_B2ms"
这是错误文本。
A positional parameter cannot be found that accepts an argument
我的问题是如何在管道 YAML 文件中添加带有下划线的参数值?
PS参数如下
[CmdletBinding()]
param (
#Subscription ID
[Parameter(Mandatory=$true)]
[string]
$azSubscriptionId,
#ResourceGroupName
[Parameter(Mandatory=$true)]
[string]
$azResourceGroupName,
#MotherSnapshotName
[Parameter(Mandatory=$true)]
[string]
$azSnapshotName,
#NewVMOSDiskName
[Parameter(Mandatory=$true)]
[string]
$azNewOSDiskName,
#VM Storage Type
[Parameter(Mandatory=$true)]
[string]
$azVMStorageType,
#VM Location
[Parameter(Mandatory=$true)]
[string]
$azVMLocation,
#VM Network
[Parameter(Mandatory=$true)]
[string]
$azVMNetwork,
#VM Name
[Parameter(Mandatory=$true)]
[string]
$azVMName,
#VM Size
[Parameter(Mandatory=$true)]
[string]
$azVMSize
)
任何帮助将不胜感激。
【问题讨论】:
-
提供错误文本会很有用。
-
嗨@askwizard,我可以成功地在参数中使用_。能否请您删除下划线并再试一次,然后在这里分享结果?此外,请将变量 system.debug 设置为 true,然后在此处分享完整的详细日志。谢谢。
-
没有这两个值的参数可以创建VM,只有当我在yaml文件中添加这两个参数值时才会出现问题。
-
嗨@askwizard,您使用的是哪个代理,托管代理还是自托管代理?您能否与我们分享完整的 .ps1 文件和详细日志?我需要检查日志并帮助你。谢谢。
标签: powershell azure-devops yaml azure-pipelines