简体   繁体   中英

VSTS Task Group Powershell Parameter

I created VSTS Task Group with Azure Powershell Task Inline Script with Four Parameters. I have added this Task Group to Release Definition and configured parameters. When i try to release it failed with following error

2018-03-23T10:28:42.2811600Z ##[error]At C:\\Users\\buildguest\\AppData\\Local\\Temp\\6e927620-8956-47d6-b926-00d9177a4c26.ps1:2 char:9 + [String] Container-Service, + ~ Parameter declarations are a comma-separated list of variable names with optional initializer expressions.

At C:\\Users\\buildguest\\AppData\\Local\\Temp\\6e927620-8956-47d6-b926-00d9177a4c26.ps1:2 char:9 + [String] Container-Service, + ~ Missing ')' in function parameter list.

Here is Azure Powershell Script

 Param(  
[String] $(apiManagementRg),   
[String] $(apiManagementName),     
[String] $(swaggerUrl),     
[String] $(basePath),   
[String] $(apiId)
)

$ApiMgmtContext = New-AzureRmApiManagementContext -ResourceGroupName $(apiManagementRg) -ServiceName $(apiManagementName)
Import-AzureRmApiManagementApi -Context $ApiMgmtContext -SpecificationFormat "Swagger" -SpecificationUrl $(swaggerUrl) -Path $(basePath) -ApiId $(apiId)

Release Definition Screenshot Release Definition

It's mainly caused by the PowerShell script syntax errors.

Based on your script, it seems $(apiManagementRg) , $(apiManagementName) , $(swaggerUrl) , $(basePath) and $(apiId) are variables defined in your release definition.

To use the user defined variables from the release definition into Powershell script parameters, you should specify the user defined variables in Script Arguments to pass the values into your PowerShell parameters.

Detail steps as below:

  • Remove the task group you created.
  • Re-create task group with Azure PowerShell Task as below:

    Inline Script:

     Param( [String] $Rg, [String] $Name, [String] $Url, [String] $path, [String] $apiId ) $ApiMgmtContext = New-AzureRmApiManagementContext -ResourceGroupName $Rg -ServiceName $Name Import-AzureRmApiManagementApi -Context $ApiMgmtContext -SpecificationFormat "Swagger" -SpecificationUrl $url -Path $path -ApiId $apiId 

    Script Arguments:

     -Rg "$(apiManagementRg)" -Name "$(apiManagementName)" -Url "$(swaggerUrl)" -path "$(basePath)" -apiId "$(apiId)" 

    在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM