[英]TFS 2018 - Custom Build Task with boolean parameters
我为TFS 2018创建了一个自定义构建任务及其扩展。我的两个参数是布尔值。 在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。
这是我的动力壳
[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中将其卸载,然后再次安装所有内容即可。
组合测试
不知道这是否仍然有意义,或者您是否已经找到解决方案。
只是提供答案是因为几天前我遇到了同一问题。
遇到相同的错误,并且TFS似乎将其输入存储为字符串。 对我来说,解决方案是在执行的PS1脚本中将-AsBool
添加到变量/参数的声明中:
[CmdletBinding()]
[bool]$ExcludeGated = Get-VstsInput -Name ExcludeGated -AsBool
但是,这确实需要使用Get-VstsInput
附带的功能Get-VstsInput
VstsInput
此特定布尔值的JSON部分看起来像一个标准条目:
{
"name": "ExcludeGated",
"type": "Boolean",
"label": "Gated Exclusion flag",
"defaultValue": "true",
"required": false,
"helpMarkDown": "your helpful markdown comment here"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.