如何将带有特殊字符的连接字符串作为参数传递给Azure DevOps中的PowerShell任务 [英] How to pass connection string with special characters as a parameter to PowerShell task in Azure DevOps

查看:51
本文介绍了如何将带有特殊字符的连接字符串作为参数传递给Azure DevOps中的PowerShell任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将连接字符串作为参数传递给power-shell任务,但是它给出错误:

I am trying to pass connection string to power-shell task as an argument but it gives error:

无法将值转换为类型System.String

Cannot convert value to type System.String

示例连接字符串:

Data Source=abc:abc-abc-abc-abc.abc.abc.abc,7458;Abc abc=abc;abc ac=ac-abc@abc-abc-ab-ab;Abc=Abc#345abc;Abc Ab=60

致电:

-BlueConnection $(CONNECTION_BLUE) -GreenConnection $(CONNECTION_GREEN)

Powershell文件abc.ps1

Powershell file abc.ps1

Param(
[Parameter(Mandatory = $true)]
[string]$BlueConnection,
[Parameter(Mandatory = $true)]
[string]$GreenConnection
)

echo "Hi  $BlueConnection"

给出以下错误:

无法将值转换为类型System.String

Cannot convert value to type System.String

推荐答案

-BlueConnection $(CONNECTION_BLUE)-GreenConnection $(CONNECTION_GREEN)应该为 -BlueConnection"$(CONNECTION_BLUE)"-GreenConnection"$(CONNECTION_GREEN)"

就像任何时候传递命令行参数一样,如果它包含空格或特殊字符,则需要将其用引号引起来.

Just like any time you're passing command line arguments, you need to wrap it in quotes if it contains spaces or special characters.

这篇关于如何将带有特殊字符的连接字符串作为参数传递给Azure DevOps中的PowerShell任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆