TFS 2018 - 使用布尔参数

时间:2018-02-06 13:57:38

标签: powershell custom-build-step tfs2018

我已经为TFS 2018创建了一个自定义构建任务及其扩展。我的两个参数是boolean。在task.json上,我将默认值设置为false。当我使用我的任务执行构建定义时,我收到以下错误:

  

System.Management.Automation.ParameterBindingArgumentTransformationException:   无法处理参数' isToDeploy'的参数转换。   无法转换值" System.String"输入" System.Boolean"。布尔   参数只接受布尔值和数字,例如$ True,   $ False,1或0. --->   System.Management.Automation.ArgumentTransformationMetadataException:   无法转换值" System.String"输入" System.Boolean"。布尔   参数只接受布尔值和数字,例如$ True,   $ False,1或0. --->   System.Management.Automation.PSInvalidCastException:无法转换   值" System.String"输入" System.Boolean"。布尔参数   仅接受布尔值和数字,例如$ True,$ False,1或0。

这是我的powershell

[CmdletBinding()]
param(
    [string][Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()] $qaApiEndpoint,
    [string][Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()] $deployfxEndpoint,
    [bool][Parameter(Mandatory=$true)] $isToDeploy,
    [string][Parameter(Mandatory=$false)] $deploymentType,
    [string][Parameter(Mandatory=$false)] $environment,
    [bool][Parameter(Mandatory=$false)] $isToArchivePackage,
    [string][Parameter(Mandatory=$false)] $archiveLocation
)

这是我的Task.json(输入部分)(忽略???因为此任务仍在开发中)

"inputs": [
    {
      "name": "qaApiEndpoint",
      "type": "string",
      "label": "QA Web API Endpoint",
      "defaultValue": "",
      "required": true,
      "helpMarkDown": "Endpoint for the QA Web API.",
      "groupName": "GeneralGroup"
    },
    {
      "name": "deployfxEndpoint",
      "type": "string",
      "label": "Deploy Fx Endpoint???",
      "defaultValue": "",
      "required": true,
      "helpMarkDown": "???",
      "groupName": "GeneralGroup"
    },
    {
      "name": "isToDeploy",
      "type": "boolean",
      "label": "Deploy?",
      "defaultValue": false,
      "required": false,
      "helpMarkDown": "Should the task perform the application's deployment?",
      "groupName": "DeploymentGroup"
    },
    {
      "name": "deploymentType",
      "type": "string",
      "label": "Deployment Type",
      "defaultValue": "",
      "required": false,
      "helpMarkDown": "Ex: Full, Update, Patch",
      "groupName": "DeploymentGroup"
    },
    {
      "name": "environment",
      "type": "string",
      "label": "Environment to deploy",
      "defaultValue": "",
      "required": false,
      "helpMarkDown": "Ex: DEV, TST, QA, PRD",
      "groupName": "DeploymentGroup"
    },
    {
      "name": "isToArchivePackage",
      "type": "boolean",
      "label": "Archive Package?",
      "defaultValue": false,
      "required": false,
      "helpMarkDown": "Should the package be archived?",
      "groupName": "PackageGroup"
    },
    {
      "name": "archiveLocation",
      "type": "string",
      "label": "Archive Location",
      "defaultValue": "",
      "required": false,
      "helpMarkDown": "Path for the package archive",
      "groupName": "PackageGroup"
    }
  ]

就像错误消息所说的那样,我已经尝试将值在Task.json中更改为$ False,0甚至" false"。我也尝试将类型更改为bool,甚至将json和powershell中的参数更改为string,然后将值转换为powershell中的boolean。我的所有尝试都以同样的错误结束了。

有一点甚至更奇怪的是,我已经从powershell和json中删除了布尔但我得到了同样的错误......这根本没有任何意义,让我怀疑我是否遇到了一些缓存问题或者其他的东西。 (是的,我在某些时间之间重新启动了机器。)

==编辑==

上面发生了奇怪的行为,因为我没有更新task.json和vss-extension.json id。需要在每次尝试之间进行。

==结束编辑==

我采取的方式"更新"我的海关任务是,我只是删除构建定义中的任务,从集合中删除扩展并从TFS卸载它,然后我再次安装所有内容。

测试组合

  • 布尔和假
  • 布尔值和0
  • 布尔和"假"
  • 布尔值和$ False
  • 布尔和" $ False"
  • 布尔和" $ false"
  • 布尔值和$ false
  • bool和0

1 个答案:

答案 0 :(得分:2)

不确定这是否仍然有用或是否已经找到解决方案。

提供答案是因为几天前我遇到了同一问题。

出现相同的错误,并且TFS似乎将其输入存储为字符串。对我来说,解决方案是在执行的PS1脚本中的变量/参数声明中添加[CmdletBinding()] [bool]$ExcludeGated = Get-VstsInput -Name ExcludeGated -AsBool

Get-VstsInput

但这确实需要使用VstsTaskSdk随附的功能{ "name": "ExcludeGated", "type": "Boolean", "label": "Gated Exclusion flag", "defaultValue": "true", "required": false, "helpMarkDown": "your helpful markdown comment here" }

此特定布尔值的JSON部分看起来像一个标准条目:

{{1}}
相关问题