Replace value of Octopus parameter within Powershell script

Hi, I need some help with Octopus parameters. I have a Powershell script that updates a configuration file as part of software deployment. The parameter is for the release number of the software, which contains a full stop i.e. 1.0 and I need to know the script to edit this value, making it 1_0. Please can you help.

I have tried a few different variations and have not been able to get it to work. My script is below. Everything else in the script works OK, I just can’t figure out how to amend the release value (the bit in bold below).

$appDirectory = $OctopusParameters["Octopus.Tentacle.Agent.ApplicationDirectoryPath"]
$version = $OctopusParameters["Octopus.Release.Number"]

$ConfigFile = "$appDirectory\path to .config file"

**$verconvert = $OctopusParameters["Octopus.Release.Number"]) - Replace(".","_")**

$content = [System.IO.File]::ReadAllText($ConfigFile).Replace("Initial Catalog=DBNAME;","Initial Catalog=DSXv" + $verconvert + "_Release;")

Hi Paul,

The script below shows how you can do this:

// Simulate the OctopusParameters collection
$OctopusParameters = New-Object 'System.Collections.Generic.Dictionary[String,String]' (,[System.StringComparer]::OrdinalIgnoreCase)
$OctopusParameters[“Octopus.Release.Number”] = "1.0"

$verconvert = $OctopusParameters[“Octopus.Release.Number”].Replace(".","_")

Write-Host $verconvert

Hope that helps.

Hi Robert, that’s great - thank you. Appreciate the quick reply!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.