Scripts unable to fin PSscriptroot after upgrade to 2021.1

The solution recommended to us with the release 2020.6.4722 is not working after upgrading to Octopus 2021.1.

We have a deployment that is bootstrapped together with Cake scripts and Powershell.

This worked previously to 2020.6
[Parameter()][string]$sourcePackagePath = “$($PSScriptRoot)…\UpdatePackages”

The statement we added to make 2020.6.4722 work is:
$sourcePackagePath = Join-Path $PSScriptRoot -ChildPath $sourcePackagePath

This no longer works when upgraded to 2021.1

Code:
Write-Host $sourcePackagePath
Write-Host “================”
$sourcePackagePath = Join-Path $PSScriptRoot -ChildPath $sourcePackagePath
Write-Host $sourcePackagePath
Write-Host “================”
Write-Host $PSScriptRoot

$sourcePackagePath = Join-Path $PSScriptRoot -ChildPath “…\UpdatePackages”;
$filter = “" + $selectedProvider + ".update*”;
$filesToEnable = Get-ChildItem -Recurse -File -Path $sourcePackagePath -Filter $filter;

Log:
Extracting package
July 19th 2021 16:55:32Info
…\UpdatePackages\
July 19th 2021 16:55:32Info

July 19th 2021 16:55:32Info
C:\Octopus\Work\20210719225526-157392-112\Scripts…\UpdatePackages\
July 19th 2021 16:55:32Info

July 19th 2021 16:55:32Info
C:\Octopus\Work\20210719225526-157392-112\Scripts
July 19th 2021 16:55:32Error
ObjectNotFound: Cannot find path ‘C:\Octopus\Work\20210719225526-157392-112\U’ because it does not exist.

I have tried to go back to the code before 2020.6.4722 and error is the same.

Please advise what has changed with PSscriptroot from 2020.6.4722 to Octopus 2021.1.

Hi @ktornow,

Thanks for getting in touch! Sorry to see you’re hitting this unexpected and inconsistent issue. I’m not aware of any changes with PSscriptroot between these versions. While I’m able to reproduce the Cannot find path error, it’s a bit different in that it’s pointing to a different subdirectory, i.e. 'C:\Octopus\newops\Work\20210720012101-86238-34\â?▌\' which seems to be due to the single ellipsis character (…) in the -ChildPath. I can’t reproduce this in the exact same way, which has me a bit perplexed. Is it possible there could be a copy/paste issue of some sort here?

I’m wondering if you instead use an Octopus populated and supplied system variable, Octopus.Action.Package[PackageID].ExtractedPath, might work and be easier to use. When referencing a package in this way on a script step, this variable will populate to the work dir.

If you’re still hitting this same issue, do you hit this same behavior when taking Octopus out of the equation and run the script directly on the box?

Lastly, I think the most helpful info would be verbose task log with debugging variables enabled. This will give us a more detailed look in the process and context.

We’ll be happy to have a look in that log, and you can email them privately to use at support@octopus.com

I look forward to hearing back!

Best regards,

Kenny

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