Octopus Deploy 中的 Powershell 变量替换

标签 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

这会在修订版 #{Octopus.Release.Number} 的 newrelic 中生成部署.我也试过使用 $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']

关于Octopus Deploy 中的 Powershell 变量替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23649055/

相关文章:

java - Jenkins Octopus 集成

powershell - Octopus Deploy - 用于在 IIS 上设置 SSL 绑定(bind)的 Deploy.ps1 脚本

powershell - 搜索邮箱SearchQuery不起作用

powershell - Powershell 中 'set -e'(出现任何错误时退出)的等价物是什么?

nuget - 为 Octopus 部署创建 nuget 包

nuget - 指定 Octopack nuget 包文件的目标路径

powershell - 使用经过转换的 web.config 发布后更新 Azure CSPKG

c# - 如何使用与其他 DLR 语言类似的 API 在 c# 应用程序中托管 PowerShell 3.0

powershell - 动态生成命令行命令,然后使用powershell调用

powershell - 目的地的复制项目问题