Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in Azure Pipeline when Get-ProjectName returns multiple items #134

Open
Jaykul opened this issue Sep 14, 2022 · 0 comments · May be fixed by #135
Open

Error in Azure Pipeline when Get-ProjectName returns multiple items #134

Jaykul opened this issue Sep 14, 2022 · 0 comments · May be fixed by #135

Comments

@Jaykul
Copy link

Jaykul commented Sep 14, 2022

We're getting an error "Cannot process argument transformation on parameter 'Value'. Cannot convert value to type System.String." when Set-BuildEnvironment calls Set-AzurePipelinesVariable with the value of ProjectName which is an array.

Quick fix: since Set-AzurePipelinesVariable requires a string, you should cast the value explicitly:

Set-AzurePipelinesVariable -Name $prefixedVar -Value $BuildHelpersVariables[$VarName]

Needs to be:

Set-AzurePipelinesVariable -Name $prefixedVar -Value "$($BuildHelpersVariables[$VarName])"

or:

Set-AzurePipelinesVariable -Name $prefixedVar -Value ([string]$BuildHelpersVariables[$VarName])

Root cause: we've been using BuildHelpers for a long time with no problems -- even on non-module projects. Today we upgraded from 2.0.3 to 2.0.16 and this new discovery case in Get-ProjectName caused the problem.

        #PSD1 in root of project but name doesn't match
        #very ick or just an icky time in Azure Pipelines
        elseif ( $PSDs = Get-ChildItem -Path $Path "*.psd1" )
        {
            if ($PSDs.count -gt 1) {
                Write-Warning "Found more than one project manifest in the root folder"
            }
            $result = $PSDs.BaseName
        }

Until now, we've been falling through to the default $result = Split-Path $Path -Leaf value, which was fine, because we're in a multi-checkout project, so our folder is named with the project name.

Now, our ScriptAnalyzerSettings.psd1 and our RequiredModules.psd1 and a couple of other similar configuration files are being treated as the project name(s) -- resulting in multiple items being returned, all of which are wrong -- and this error when the call to Set-AzurePipelinesVariable assumes a string result.

My recommendation is to fix the call to Set-AzurePipelinesVariable as I suggested above, but also to consider that if you found multiple results from looking at psd1 files, they are definitely not the right value and you should keep looking (and fall through to the folder name).

 ErrorRecord       : 
        Exception             : 
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : Cannot process argument transformation on parameter 'Value'. Cannot convert value to type System.String.
            HResult : -2146233087
        CategoryInfo          : InvalidData: (:) [Set-AzurePipelinesVariable], ParentContainsErrorRecordException
        FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-AzurePipelinesVariable
        InvocationInfo        : 
            MyCommand        : Set-AzurePipelinesVariable
            ScriptLineNumber : 126
            OffsetInLine     : 70
            HistoryId        : 1
            ScriptName       : C:\Program Files\WindowsPowerShell\Modules\BuildHelpers\2.0.16\Public\Set-BuildEnvironment.ps1
            Line             :                 Set-AzurePipelinesVariable -Name $prefixedVar -Value $BuildHelpersVariables[$VarName]
            PositionMessage  : At C:\Program Files\WindowsPowerShell\Modules\BuildHelpers\2.0.16\Public\Set-BuildEnvironment.ps1:126 char:70
                               + … esVariable -Name $prefixedVar -Value $BuildHelpersVariables[$VarName]
                               +                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            PSScriptRoot     : C:\Program Files\WindowsPowerShell\Modules\BuildHelpers\2.0.16\Public
            PSCommandPath    : C:\Program Files\WindowsPowerShell\Modules\BuildHelpers\2.0.16\Public\Set-BuildEnvironment.ps1
            CommandOrigin    : Internal
        ScriptStackTrace      : at Set-BuildEnvironment, C:\Program Files\WindowsPowerShell\Modules\BuildHelpers\2.0.16\Public\Set-BuildEnvironment.ps1: line 126
                                at <ScriptBlock>, D:\Agents\Agent1\_work\17\s\InvokeBuildTasks\Initialize.ps1: line 4
                                at <ScriptBlock>, D:\Agents\Agent1\_work\17\s\SharedInfrastructureModules\Bicep.build.ps1: line 22
                                at <ScriptBlock><End>, C:\Program Files\WindowsPowerShell\Modules\InvokeBuild\5.8.0\Invoke-Build.ps1: line 655
                                at <ScriptBlock>, D:\Agents\Agent1\_work\17\s\SharedInfrastructureModules\init.ps1: line 24
                                at <ScriptBlock>, D:\Agents\Agent1\_work\_temp\59cf28f5-e8a3-41af-b6d3-6b2866b97e99.ps1: line 3
                                at <ScriptBlock>, <No file>: line 1

@Jaykul Jaykul linked a pull request Sep 14, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant