繁体   English   中英

Powershell sql 部署脚本不适用于环境变量

[英]Powershell sql deploy script is not working with env variavle

我在constants.groovy文件中有以下行:

myMap = [
    "TEST":["SQL_URL":"Data Source=TEST,123", "credential":"" ]
]

jenkinsfile.groovy中的这一行:

bat "powershell.exe -file pipeline/powershell/deploy_sql.ps1 ${myMap[env.Environment_Type].SQL_URL}"

deploy_sql.ps1中的这一行:

$Env = $args[0]
$msbuild = Start-Process -FilePath "msbuild" -ArgumentList '"Database Services\Database Services.sqlproj"','/t:deploy','/p:Configuration=Release','/p:TargetConnectionString="Data Source="+$Env+";Integrated Security=True;Persist Security Info=False;Pooling=False;MultipleActiveResultSets=False;Connect Timeout=60;Encrypt=False;TrustServerCertificate=False"','/p:BlockOnPossibleDataLoss=True','/p:TargetDatabase="bnhp_fsdb"','-fl','-flp:logfile=msbuild.log' -wait -PassThru

但我在日志中收到此错误:

Deploy error Deploy72002: Unable to connect to target server '+$Env+'. Please verify the connection information such as the server name, login credentials, and firewall rules for the target server.

当我使用完整的硬编码数据源运行时,它可以工作,所以我猜 powershell 语法有问题

PowerShell 字符串文字有两种形式:逐字可扩展

逐字字符串文字由单引号 ( ' ) 包围,可扩展字符串由双引号 ( " ) 包围。

将受影响的字符串文字转换为可扩展字符串需要我们:

  • 将周围的引号更改为"
  • 通过将它们加倍来转义字符串中的所有文字"
  • 使用` (反引号)转义任何剩余的特殊字符

在您的情况下,我们将更改:

'/p:TargetConnectionString="Data Source="+$Env+";Integrated Security=True;Persist Security Info=False;Pooling=False;MultipleActiveResultSets=False;Connect Timeout=60;Encrypt=False;TrustServerCertificate=False"'

至:

"/p:TargetConnectionString=""Data Source=${Env};Integrated Security=True;Persist Security Info=False;Pooling=False;MultipleActiveResultSets=False;Connect Timeout=60;Encrypt=False;TrustServerCertificate=False"""

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM