Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sebgod/6b3c42a38a2c3435e51ef4a4ea621271 to your computer and use it in GitHub Desktop.
Save sebgod/6b3c42a38a2c3435e51ef4a4ea621271 to your computer and use it in GitHub Desktop.
# replace Octopus variables in host.json
$octoVariableRegEx = [regex]"#\{([A-Za-z0-9_]+)\}"
$matchEvaluator = {
$varName = $args[0].Groups[1]
$octoValue = $global:OctopusParameters[$varName]
if ($null -ne $octoValue) { $octoValue } else { "$varName NOT DEFINED!" }
}
$hostJsonFiles = Get-ChildItem -Recurse $functionPackage -Filter 'host.json'
if ($hostJsonFiles.Count -gt 0) {
$hostJsonFile = $hostJsonFiles[0].FullName
$hostJsonOrig = Get-Content $hostJsonFile -Raw
$hostJsonReplaced = $octoVariableRegEx.Replace($hostJsonOrig, $matchEvaluator)
$hostJsonReplaced | Set-Content $hostJsonFile
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment