We have a deployment that is bootstrapped together with Cake scripts and Powershell. Since upgrading to Octopus 2020.6.4722 last Friday, we are unable to deploy that project. I’ve been troubleshooting the scripts and found the $PSScriptRoot variable as at least one of the culprits. I added a line to concatenate the $PSScriptRoot to the -ChildPath of the folder using Join-Path. Now I’m finding more missing folders in the deployment. Is this a known bug in that release of Octopus? If so, is there a workaround or fix?
This used to work
[Parameter()][string]$sourcePackagePath = “$($PSScriptRoot)…\UpdatePackages”
Now I had to add this statement in the script
$sourcePackagePath = Join-Path $PSScriptRoot -ChildPath $sourcePackagePath
Which folders are you finding that are missing in your deployment?
Would you be able to give me more details about the step that’s running into this issue as well as what your end goal with the step is?
It sounds like you are running a script inside of a package and trying to reference the script location within the script to set a location, but I want to be sure.
Do you know what version you were on previous to this where it worked?
If possible, can you send me screenshots of your step as well as attach the script itself as a ps1/txt so I can attempt to reproduce the behavior on my end? Please feel free to DM me these for privacy reasons if necessary.
Jeremy, we were on version 2019.9.12. And yes this is a package deploy trying to run a script within the package and attempting to get to the script location and various folders relative to it. This is the first error we saw and it was trying to get to the UpdatePackages folder.
The structure is running a ps1 under the Scripts folder, trying to get back to UpdatePackages a the same level as the Scripts folder.
This is just 1 of our scripts using that variable and after I fixed this one with the Join-Path command, it proceeded to several others that are now broken also.
I wonder if the temp folder name under the Octopus\work is what is missing now.
19:41:53 Info | C:\Octopus\CloudPollingJeremyMSpace\Work\20210415194147-67764-54\..\UpdatePackages\
19:41:53 Info | C:\Octopus\CloudPollingJeremyMSpace\Work\20210415194147-67764-54\C:\Octopus\CloudPollingJeremyMSpace\Work\20210415194147-67764-54\..\UpdatePackages\
As you can, see the first line correctly points to the subfolder within the working directory as indicated, and the second results in a duplicate path.
Please let me know if I missed something in my reproduction. If not, I can try to spin up your identical version and repeat the steps above.
This looks close and can you add a write-Host of the $PSScriptRoot? I used the same variable to concatenate the PSScriptRoot to, so that the rest of the script would have the correct value in it. Your example is working with the full path, so when you concatenate it to itself, it does double it.
20:18:00 Info | C:\Octopus\CloudPollingJeremyMSpace\Work\20210415201755-67775-60\..\UpdatePackages\
20:18:00 Info | ================
20:18:00 Info | C:\Octopus\CloudPollingJeremyMSpace\Work\20210415201755-67775-60\C:\Octopus\CloudPollingJeremyMSpace\Work\20210415201755-67775-60\..\UpdatePackages\
20:18:00 Info | ================
20:18:00 Info | C:\Octopus\CloudPollingJeremyMSpace\Work\20210415201755-67775-60
Am I missing anything from my repro that I should add in?
No, sorry, this is still 2021.1.6460. I wanted to make sure I wasn’t missing anything in my reproduction by confirming my steps with you. Everything is identical on your side? Which version of PowerShell is the worker/tentacle running?
Thank you for attempting to recreate it. I have modified all our scripts to reset the variables using the Join-Path of $PSScriptRoot and the -ChildPath that was originally intended by the concatenation. I removed the Join-Path that used the -ChildPath of the whole original variable. That prevents the duplication, but still doesn’t explain why this stopped working with this Octopus upgrade. Since you have proven the Octopus release itself is not the culprit, I won’t immediately upgrade to the latest LTS. Thank you for your help Jeremy. I wish I had a warm fuzzy about the resolution, but at least it is resolved for now.
This feels like it may be a PowerShell issue on the local box.
What happens if you copy paste my script above and save it as a ps1 on the local box and run it? Do you get the correct output or do you also get unexpected paths there?
If I don’t hear from you, I hope you have a great weekend.