[英]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.