Octopus Deploy 中的 Powershell 变量替换

4

我有一个非常简单的PowerShell脚本,用于在特定组件完成部署后通知Newrelic。我的问题是,我无法正确地发送发布版本号。

我使用的脚本是:

$NewRelicUri = "https://api.newrelic.com/deployments.xml"
$body = @{ 
    "deployment[app_name]" = "PB.Website"; 
    "deployment[revision]"= "#{Octopus.Release.Number}"; 
} 

Write-Host "Sending notification to $NewRelicUri..."
Invoke-WebRequest -Uri $NewRelicUri -Headers @{ "x-api-key"="XXX" } -Method Post -Body $body -UseBasicParsing

这将在newrelic中生成一个部署,版本号为#{Octopus.Release.Number}。我还尝试使用$OctopusParameters['Octopus.Release.Number']的长手写版本,但这会生成一个带有版本号System.Collections.Generic.Dictionary``2[System.String,System.String]['Octopus.Release.Number']的部署。
如何让Octopus将实际的发布号发送到newrelic?

1
不使用newrelic,所以我无法真正测试,但我会尝试这样做:"deployment[revision]"= "$($OctopusParameters['Octopus.Release.Number'])" - mjolinor
做得好!能不能把你的评论移到回答里,这样我就可以接受了? - ilivewithian
完成。很高兴问题解决了! - mjolinor
1个回答

6

我不使用NewRelic,所以无法进行真正的测试,但你在长手版本中遇到的错误表明你需要使用子表达式来表示该值:

 "deployment[revision]"= "$($OctopusParameters['Octopus.Release.Number'])" 

如果版本号已经是字符串,您可能只需要使用以下代码:
"deployment[revision]" = $OctopusParameters['Octopus.Release.Number']

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接