簡體   English   中英

如何在 Azure DevOps PowerShell Pipeline 任務中添加帶下划線的參數值

[英]How to add argument values with underscore in Azure DevOps PowerShell Pipeline task

我有一個帶有多個參數的 Azure DevOps Pipeline 來創建 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

如果我添加以下兩個參數值 Pipeline Execution Error Out 並且我知道這是由於下划線而發生的,因為其他值中沒有任何下划線並且沒有問題。 只有當該值具有如下下划線時,它才會在管道執行時給出錯誤。

    -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

)

任何幫助將不勝感激。

根據文檔:用戶定義的變量可以由字母、數字、. 和 _ 字符組成。 我可以在管道 YAML 文件中成功使用帶下划線的添加參數值。 樣本:

PowerShell.ps1

[CmdletBinding()]
param (
    
    #Subscription ID
    [Parameter(Mandatory=$true)]
    [string]
    $test01,
    
    #ResourceGroupName
    [Parameter(Mandatory=$true)]
    [string]
    $test02,

    #MotherSnapshotName
    [Parameter(Mandatory=$true)]
    [string]
    $test03

)

 Write-Host "test01 is" $test01
 Write-Host "test02 is" $test02
 Write-Host "test03 is" $test03

YAML 構建:

steps:
- task: AzurePowerShell@5
  inputs:
    azureSubscription: 'Microsoft Azure Internal Consumption (daaeef3e-d7fe-49e8-baaa-b3df9d072825)'
    ScriptType: 'FilePath'
    ScriptPath: 'powershell.ps1'
    ScriptArguments: '-test01 "test" -test02 "Just_a_test" -test03 "Just a test"'
    azurePowerShellVersion: 'LatestVersion'

結果:

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM