我有一个非常简单的 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'] 修订版的部署

我怎样才能让八达通把实际的发布号发送到newrelic?

最佳答案

我不使用 NewRelic,所以我无法真正测试它,但是您在长手版本中获得的错误表明您需要为该值使用子表达式:

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

如果版本号已经是字符串,你可能只需要:
"deployment[revision]" = $OctopusParameters['Octopus.Release.Number']

10-08 08:52