Created
November 23, 2021 21:28
-
-
Save sebgod/6b3c42a38a2c3435e51ef4a4ea621271 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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