VSTS任务组Powershell参数 [英] VSTS Task Group Powershell Parameter

查看:86
本文介绍了VSTS任务组Powershell参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用带有四个参数的Azure Powershell任务内联脚本创建了VSTS任务组.我已将此任务组添加到发布定义"和配置的参数中.当我尝试释放它时,出现以下错误

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 ## [错误]在 C:\ Users \ buildguest \ AppData \ Local \ Temp \ 6e927620-8956-47d6-b926-00d9177a4c26.ps1:2 字符数:9 + [String]容器服务, +〜参数声明是用逗号分隔的变量名称列表,带有可选的初始化程序表达式.

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.

在 C:\ Users \ buildguest \ AppData \ Local \ Temp \ 6e927620-8956-47d6-b926-00d9177a4c26.ps1:2 字符数:9 + [String]容器服务, +〜函数参数列表中缺少')'.

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

这是Azure Powershell脚本

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)

发布定义屏幕截图 发布定义

推荐答案

主要由PowerShell脚本语法错误引起.

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

根据您的脚本,似乎$(apiManagementRg)$(apiManagementName)$(swaggerUrl)$(basePath)$(apiId)是您的发行版定义中定义的变量.

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

要将发布定义中的用户定义变量用于Powershell脚本参数,应在脚本参数中指定用户定义变量,以将值传递到PowerShell参数中.

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.

详细步骤如下:

  • 删除您创建的任务组.
  • 使用Azure PowerShell任务重新创建任务组,如下所示:

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

内联脚本:

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

脚本参数:

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

这篇关于VSTS任务组Powershell参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆