MethodsAndPractices / vsteam

PowerShell module for accessing Azure DevOps Services and Azure DevOps Server (formerly VSTS or TFS)
https://methodsandpractices.github.io/vsteam-docs/
MIT License
442 stars 155 forks source link

Incorrect parameter type for List parameters in Get-VsTeamBuild cmdlet #541

Closed Bazaleev closed 11 months ago

Bazaleev commented 11 months ago

Steps to reproduce

Get-VsTeamBuild -ResultFilter 'succeeded','partiallysucceeded' -ProjectName 'projectname'

Expected behavior

I expected that I get back builds with requested results.

Actual behavior?

Cmdlet execution fails with

Get-VSTeamBuild: Cannot process argument transformation on parameter 'ResultFilter'. Cannot convert value to type System.String.

And if I pass values as string with coma separated values e.g. 'succeeded,partiallysucceeded' it fails as expected on parameter validation.

Get-VSTeamBuild: Cannot validate argument on parameter 'ResultFilter'. The argument "succeeded,partiallysucceeded" does not belong to the set "succeeded,partiallySucceeded,failed,canceled" specified by the ValidateSet attribute. Supply an argument that is in the set and then try the command again.

You'd need to switch parameter type from [string] to [string[]] and use -join operator in the place it's used.

On Which OS have you tried it?

Windows

What was your server version?

Azure DevOps Services

Other server version

No response

Log output of used API

Billing                     : 5.1-preview.1
Build                       : 5.1
Core                        : 5.1
DistributedTask             : 6.0-preview
DistributedTaskReleased     : 5.1
ExtensionsManagement        : 6.0-preview
Git                         : 5.1
Graph                       : 6.0-preview
HierarchyQuery              : 5.1-preview
MemberEntitlementManagement : 6.0-preview
Packaging                   : 6.0-preview
Pipelines                   : 5.1-preview
Policy                      : 5.1
Processes                   : 6.0-preview
Release                     : 5.1
ServiceEndpoints            : 5.0-preview
TaskGroups                  : 6.0-preview
Tfvc                        : 5.1
VariableGroups              : 5.1-preview.1
Version                     : VSTS
Wiki                        : 6.0
WorkItemTracking            : 6.0-preview.1

Log output of $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.3.6
PSEdition                      Core
GitCommitId                    7.3.6
OS                             Microsoft Windows 10.0.22621
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
mnieto commented 11 months ago

As per my understanding after reading the documentation, the API to list the builds doesn't support multiple result states in the query string, and therefore the Get-VsTeamBuild cmdlet does not support that either. If you specify multiple values in the API call, it simply ignores the 'bad' paramter.

A workarround for this is to add the results to a list:

$builds = @()
$builds += Get-VsTeamBuild -ResultFilter 'succeeded' -ProjectName 'projectname'
$builds += Get-VsTeamBuild -ResultFilter 'partiallysucceeded' -ProjectName 'projectname'
SebastianSchuetze commented 11 months ago

Thanks for researching @mnieto and I agree to the explanation. It is not a bug but a design limitation of the API.