VSTS Task Group Powershell Parameter

2019-07-21 04:14发布

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

1条回答
放我归山
2楼-- · 2019-07-21 04:56

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)"
    

    enter image description here

查看更多
登录 后发表回答