Home > Enterprise >  Azure DevOps - Cannot convert value "System.String" to type "System.Boolean"
Azure DevOps - Cannot convert value "System.String" to type "System.Boolean"

Time:12-22

I am creating a yml pipeline that calls a ps1 script in my repository. the signature of the function,

function New-Service-Connection-Object
{
    param(
        [Parameter(Mandatory)] [string] $clientId,
        [Parameter(Mandatory)] [string] $clientSecret,
        [Parameter(Mandatory)] [string] $tenantId,
        [Parameter(Mandatory)] [string] $url,
        [Parameter(Mandatory)] [string] $authorizationScheme,
        [Parameter()] [bool] $isReady,
        [Parameter()] [bool] $isShared,
        [Parameter(Mandatory)] [string] $serviceConnectionName,
        [Parameter(Mandatory)] [string] $type,
        [Parameter()] [string] $description
    )
# removed the code
}

I am using an inline PowerShell@2 task to call the function within my yml file. the task looks like below,

  - task: PowerShell@2
    inputs:
      targetType: 'inline'
      script: |
        . ./powershells/az-create-pp-service-connection.ps1
        write-host "File loaded"
        New-Service-Connection-Object `
        --clientId $(serviceConnection.clientId) `
        --clientSecret $(serviceConnection.clientSecret) `
        --tenantId $(serviceConnection.tenantId) `
        --url $(dataverseUrl) `
        --authorizationScheme $(serviceConnection.AuthorizationScheme) `
        --isReady $(serviceConnection.IsReady) --isShared  $(serviceConnection.IsShared)`
        --serviceConnectionName $(serviceConnection.Name) `
        --type $(serviceConnection.Type) `
        --description $(serviceConnection.Description)
    displayName: 'Running Create new service connection script'

when I run the code in DevOps I always get the following error,

Line | 8 | --tenantId `
| Cannot process argument transformation on parameter 'isReady'. Cannot | convert value "System.String" to type "System.Boolean". Boolean | parameters accept only Boolean values and numbers, such as $True, | $False, 1 or 0.

Initially, I thought its a simple parse error and I followed the resolution from the following StackOverflow questions

But I get the exact same error. the values for both the bool var isReady and isShared are set as true. i have tried with $True and $true and also 1 as the error message eluded to. i still receive the same error. I have hardcoded the value to

--isReady 1 --isShared 1 `

and

--isReady $True --isShared $True `

this yielded the same error. i have then removed the setting the values in the yml altogether. surprisingly I am getting the same error when I run the pipeline. This seems to me like the ps1 file is getting cached somehow. so I looked at the logs in the pipeline run and the file id seems to be changing on every run

New-Service-Connection-Object: /home/vsts/work/_temp/4de2f469-3d8f-4428-89db-de44eb5e0aa5.ps1:8

which means the file is not getting cached?

I am not sure what I am doing wrong. any help on this will be really appreciated.

CodePudding user response:

PowerShell uses only one hyphen (-) to specify parameters. This can be found in the documentation here: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/powershell-v2?view=azure-pipelines#call-powershell-script-with-multiple-arguments

  • Related