八达通部署中的Powershell可变替换

ili*_*ian 4 powershell octopus-deploy

我有一个非常简单的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
Run Code Online (Sandbox Code Playgroud)

这会在修订版本中生成新的部署#{Octopus.Release.Number}.我也试过使用长手版本$OctopusParameters['Octopus.Release.Number'],但这会产生一个带有修订版本的部署System.Collections.Generic.Dictionary``2[System.String,System.String]['Octopus.Release.Number']

如何让章鱼把实际发布号码发送到newrelic?

mjo*_*nor 6

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

 "deployment[revision]"= "$($OctopusParameters['Octopus.Release.Number'])" 
Run Code Online (Sandbox Code Playgroud)

如果版本号已经是字符串,那么您可能只需:

"deployment[revision]" = $OctopusParameters['Octopus.Release.Number']
Run Code Online (Sandbox Code Playgroud)