[英]TFS 2018 - Custom Build Task with boolean parameters
I've created a custom build task and its extension for TFS 2018. Two of my parameter are boolean. 我为TFS 2018创建了一个自定义构建任务及其扩展。我的两个参数是布尔值。 On task.json I set the default value to false.
在task.json上,我将默认值设置为false。 When I execute a build definition with my task I get the following error:
当我执行任务的构建定义时,出现以下错误:
System.Management.Automation.ParameterBindingArgumentTransformationException: Cannot process argument transformation on parameter 'isToDeploy'.
System.Management.Automation.ParameterBindingArgumentTransformationException:无法处理参数'isToDeploy'上的参数转换。 Cannot convert value "System.String" to type "System.Boolean".
无法将值“ System.String”转换为类型“ System.Boolean”。 Boolean parameters accept only Boolean values and numbers, such as $True, $False, 1 or 0. ---> System.Management.Automation.ArgumentTransformationMetadataException: Cannot convert value "System.String" to type "System.Boolean".
布尔参数仅接受布尔值和数字,例如$ True,$ False,1或0。---> System.Management.Automation.ArgumentTransformationMetadataException:无法将值“ System.String”转换为类型“ System.Boolean”。 Boolean parameters accept only Boolean values and numbers, such as $True, $False, 1 or 0. ---> System.Management.Automation.PSInvalidCastException: Cannot convert value "System.String" to type "System.Boolean".
布尔参数仅接受布尔值和数字,例如$ True,$ False,1或0。---> System.Management.Automation.PSInvalidCastException:无法将值“ System.String”转换为类型“ System.Boolean”。 Boolean parameters accept only Boolean values and numbers, such as $True, $False, 1 or 0.
布尔参数仅接受布尔值和数字,例如$ True,$ False,1或0。
Here is my 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
)
Here is my Task.json (input part) (ignore ??? as this task is still in development) 这是我的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"
}
]
Like the error message says, I've already tried to change the value, in Task.json, for the booleans to $False, 0 and even "false". 就像错误消息说的那样,我已经尝试在Task.json中将布尔值更改为$ False,0甚至“ false”。 I've also tried to change the type to bool instead and even change the parameters in json and powershell to string and then convert the values to boolean in powershell.
我还尝试将类型更改为bool,甚至将json和powershell中的参数更改为string,然后在powershell中将值转换为boolean。 All my tries ended up with the same error.
我所有的尝试都以相同的错误结束。
One thing even weirder is that I've deletied the booleans from powershell and json but I got the same error...which makes no sense at all and makes me question if i'm hitting some cache issue or something. 甚至更奇怪的是,我已经从powershell和json中删除了布尔值,但是我遇到了同样的错误...这根本没有道理,让我怀疑我是否遇到了某些缓存问题或其他问题。 (yes, I've restarted the machine in between some of the times).
(是的,在某些时候我已经重启了机器)。
==Edit== ==编辑==
The weird behavior above happens because I wasn't updating the task.json and vss-extension.json id. 发生上述怪异行为是因为我没有更新task.json和vss-extension.json id。 Need to do it between each try.
每次尝试之间都需要这样做。
==End Edit== ==结束编辑==
The way I do to "update" my customs task is, I simply delete the task in the build definition, delete the extension from the collection and uninstall it from TFS, then I install everything again. 我“更新”海关任务的方式是,我只需要删除构建定义中的任务,从集合中删除扩展名,然后从TFS中将其卸载,然后再次安装所有内容即可。
Combinations tested 组合测试
Not sure if this is still relevant or if you found a solution already. 不知道这是否仍然有意义,或者您是否已经找到解决方案。
Just providing an answer because I ran into the same issue a couple of days ago. 只是提供答案是因为几天前我遇到了同一问题。
Was getting the same error and it appears that TFS stores its inputs as strings. 遇到相同的错误,并且TFS似乎将其输入存储为字符串。 For me the solution was to add
-AsBool
to the declaration of my variable / parameter in the executed PS1 script: 对我来说,解决方案是在执行的PS1脚本中将
-AsBool
添加到变量/参数的声明中:
[CmdletBinding()]
[bool]$ExcludeGated = Get-VstsInput -Name ExcludeGated -AsBool
This however does require the use of function Get-VstsInput
which comes with VstsTaskSdk 但是,这确实需要使用
Get-VstsInput
附带的功能Get-VstsInput
VstsInput
The JSON part for this particular Boolean looks like a standard entry: 此特定布尔值的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.