我为 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。
这是我的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 中的参数更改为字符串,然后在 powershell 中将值转换为布尔值。我所有的尝试都以同样的错误告终。
更奇怪的一件事是,我已经从 powershell 和 json 中删除了布尔值,但我得到了同样的错误……这根本没有意义,让我怀疑我是否遇到了一些缓存问题或其他问题。(是的,我在某些时间之间重新启动了机器)。
==编辑==
发生上述奇怪行为是因为我没有更新 task.json 和 vss-extension.json id。需要在每次尝试之间进行。
==结束编辑==
我“更新”我的海关任务的方式是,我只需删除构建定义中的任务,从集合中删除扩展并从 TFS 卸载它,然后我再次安装所有内容。
测试的组合
- 布尔和假
- 布尔值和 0
- 布尔值和“假”
- 布尔值和 $False
- 布尔值和“$False”
- 布尔值和“$false”
- 布尔值和 $false
- 布尔和 0