Custom Powershell script does not execute

Hi,

I have a step that shall remove config transform files after deploy, just leaving Web.config in the folder for example. However it doesn´t seem to work. I have verified the actual script by running it in Powershell in a folder where I know there are config transform files lying around and they are infact removed by the script. The output from the log is just the result of a Write-Output I have in place at the top saying “Removing config files”, there is no error or anything but no files are removed either. The script looks like this:

Get-ChildItem . -Include *Debug.config, *Test.config, *Release.config, *Stage.config, *base.config -Recurse | foreach ($) { Remove-Item $.FullName -Force}

Have you had any issues like this before? Do I need to be more specific in my script with paths or anything in Octopus?

BR, Petra

Hi,

Thanks for reaching out. Depending from where are you executing this script, you’ll need to be more specific or not with the path. A good practice here is to first run a simple get-location to know where is the prompt standing at the time to execute the script.

Can you send me a full screenshot of the field where you included this script in your deployment process? Make it a fullscreen screenshot if possible so I can see the entire context.

Thanks,
Dalmiro

Hi,

Well, it´s a separate step (step type “Run a script”) which executes a custom Powershell script. The step runs directly after the Deploy website step (step type “Deploy a NuGet package”) so I´m not sure there´s a lot to take a screenshot of? Included a screenshot of the entire process with the steps.

BR, Petra

Hi Petra,

Your script relies on the fact that it is executed on the same path where the app was installed, which is incorrect. You do need to be more specific with your path. For this reason I recommended you to check the path first using Get-Location.

What you can do in this case is, from the step Remove config transform files, use a variable that holds the path where the code was deployed during the step Deploy Website. To do this, click on the menu icon at the left of the script box and look for a variable with the name of your deploy step on it (Deploy Website) and output.Package.InstallationDirectoryPath. Then use that variable to set the path for your script as shown on the attached GIF.

Final code should be something like this:

$InstallPath = $OctopusParameters['Octopus.Action[Deploy Website].Output.Package.InstallationDirectoryPath']

Get-ChildItem $InstallPath -Include *Debug.config, *Test.config, *Release.config, *Stage.config, *base.config -Recurse | foreach ($_) { Remove-Item $_.FullName -Force}

Hope that helps,
Dalmiro

Thank you so much! It worked like a charm!

BR, Petra