Building a checkbox in your VSTS custom build task

Update 5/25/2016

Since May 6th 2016, this is default functionality in VSTS. Look for the Checkbox Control section in this posthttps://www.visualstudio.com/news/2016-may-6-vso

Today I was building a custom build task for the new build system in VSTS. I read the documentation and started to work on the task.json.

Besides some strings I wanted to have as a parameter, I also wanted a checkbox to represent a boolean. Like here in the Publish Test results Task

1

This is pretty easy, in the task.json you can add an input of type boolean, like this

{
"name": "EnableVerboseLogging",
"type": "boolean",
"label": "Output verbose logging",
"defaultValue": "false",
"required": false,
"groupName": "output",
"helpMarkDown": "Check this option if you want extended logging enabled"
}

I use a powershell to execute the real work, I had a powershell that received a boolean as parameter, like this

param(
[bool]$EnableVerboseLogging
)

But when I executed the build task, I received an error

System.Management.Automation.ParameterBindingArgumentTransformationException: Cannot process argument transformation on parameter 'SetWorkItemNewStatus'. Cannot convert value "System.String" to type "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". 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". Boolean parameters accept only Boolean values and numbers, such as $True, $False, 1 or 0.

It seemed that the powershell script that you are calling can only receive strings. They should be converted to Boolean in the powershell script. So I changed the powershell script to.

param(
[string]$EnableVerboseLogging
)
[bool]$EnableVerboseLoggingBool= Convert-String $EnableVerboseLogging Boolean

and used the new parameter instead and everything worked fine !

Other useful links for building a custom task

2 Responses to “Building a checkbox in your VSTS custom build task”

  1. Perfect: this was exactly the fix I needed for a checkbox in my custom build step. (Y)

  2. Since the introduction of the vsts-task-lib (https://github.com/Microsoft/vsts-task-lib) this is no longer needed: a bool is now a valid parameter that does not need any further conversion. Unfortunately this is not yet a solution for on-premise TFS 2015 Update 2 users, but for VSTS this works better.