I have an Octopus project which runs a PowerShell script as one of its steps.
Based on logs in the script, I can confirm that the script runs to the last step successfully which is
# ...Rest of script before final line below
Write-Host "Deploy Complete"
However, after the script completes, the following error shows in the console:
Here is the error in written form:
Info Deploy Complete March
Error Access to the path is denied.
Error System.UnauthorizedAccessException
Error at System.IO.FileSystem.ReplaceFile(String sourceFullPath, String destFullPath, String destBackupFullPath, Boolean ignoreMetadataErrors)
Error at System.IO.File.Replace(String sourceFileName, String destinationFileName, String destinationBackupFileName, Boolean ignoreMetadataErrors)
Error at System.IO.File.Replace(String sourceFileName, String destinationFileName, String destinationBackupFileName)
Error at Calamari.Common.Plumbing.FileSystem.CalamariPhysicalFileSystem.OverwriteAndDelete(String originalFile, String temporaryReplacement) in C:\BuildAgent\work\e0cefbed4ad11812\source\Calamari.Common\Plumbing\FileSystem\CalamariPhysicalFileSystem.cs:line 493
Error at Calamari.Common.Features.Deployment.Journal.DeploymentJournal.Write(IEnumerable`1 elements) in C:\BuildAgent\work\e0cefbed4ad11812\source\Calamari.Common\Features\Deployment\Journal\DeploymentJournal.cs:line 134
Error at Calamari.Common.Features.Deployment.Journal.DeploymentJournal.AddJournalEntry(JournalEntry entry) in C:\BuildAgent\work\e0cefbed4ad11812\source\Calamari.Common\Features\Deployment\Journal\DeploymentJournal.cs:line 35
Error at Calamari.Common.Plumbing.Deployment.Journal.DeploymentJournalWriter.AddJournalEntry(RunningDeployment deployment, Boolean wasSuccessful, String packageFile) in C:\BuildAgent\work\e0cefbed4ad11812\source\Calamari.Common\Plumbing\Deployment\Journal\DeploymentJournalWriter.cs:line 39
Error at Calamari.Commands.RunScriptCommand.Execute(String[] commandLineArguments) in C:\BuildAgent\work\e0cefbed4ad11812\source\Calamari\Commands\RunScriptCommand.cs:line 97
Error at Calamari.Deployment.PackageRetention.PackageJournalCommandDecorator.Execute(String[] commandLineArguments) in C:\BuildAgent\work\e0cefbed4ad11812\source\Calamari\Deployment\PackageRetention\PackageJournalCommandDecorator.cs:line 49
Error at Calamari.Program.ResolveAndExecuteCommand(IContainer container, CommonOptions options) in C:\BuildAgent\work\e0cefbed4ad11812\source\Calamari\Program.cs:line 58
Error at Calamari.Common.CalamariFlavourProgram.Run(String[] args) in C:\BuildAgent\work\e0cefbed4ad11812\source\Calamari.Common\CalamariFlavourProgram.cs:line 78
Fatal The remote script failed with exit code 100
Fatal The action Deploy Reports to *** on ***l-QA failed
The error seems to indicate that something is failing on the Octopus Deploy side that automatically runs after the PowerShell script has run. It looks like something to do with the journal potentially.
I have ensured that the actual PowerShell script does run when I execute it locally.
I can also confirm that it does work on the DEV server, whereas the failure is on the QA server, which is strange.
Lastly, for extra context, the step is configured to run on the deployment target.
Som extra information: the Octopus version is v2022.1 (Build 2412).
Can anyone help?