Azure DevOps - 无法将值"System.String"转换为类型 "System.Boolean"



我正在创建一个调用存储库中的ps1脚本的yml管道。函数的签名

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
}

我使用内联PowerShell@2任务来调用我的yml文件中的函数。任务如下所示,

- 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'

当我在DevOps中运行代码时,我总是得到以下错误,

|8 |——tenantId '
|无法处理参数'isReady'的参数转换。不能| convert value "System.String"键入"system . boolean"。布尔|参数只接受布尔值和数字,如$True;| $False, 1或0.

最初,我认为这是一个简单的解析错误,我遵循以下StackOverflow问题的解决方案

  • 在powershell中将字符串转换为布尔值
  • 从VSTS传递bool参数到Powershell脚本

但是我得到了完全相同的错误。bool变量isReadyisShared的值都设置为true。我已经尝试了$True$true以及1作为避免的错误信息。我仍然收到相同的错误。我已经将值硬编码为

--isReady 1 --isShared 1 `

--isReady $True --isShared $True `

会产生相同的错误。然后,我完全删除了设置yml中的值。令人惊讶的是,当我运行管道时,我得到同样的错误。在我看来,ps1文件被缓存了。所以我查看了管道运行的日志,文件id似乎在每次运行时都在变化

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

这意味着文件没有被缓存?

我不确定我做错了什么。如有任何帮助,我将不胜感激。

PowerShell只使用一个连字符(-)来指定参数。这可以在这里的文档中找到:https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/powershell-v2?view=azure-pipelines call-powershell-script-with-multiple-arguments

相关内容

最新更新