Octopus Script Step Fails After the Inline Script Completes

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?

Good afternoon @JCollier,

Welcome back to our forums and I am sorry to hear you are having issues when running a PowerShell script from a step inside of Octopus directly on your deployment target.

Thank you for all of the detailed information you provided, it really helped me understand your issue.
The error message you are seeing - Error Access to the path is denied usually relates to either permissions on the folder Octopus is trying to access (or in this case your tentacle), or it might be your Antivirus blocking access to the Octopus folders on your tentacle.

To start, are you able to check the permissions on the deployment target for C:\Octopus\Work and C:\Octopus\Tools and ensure your Octopus Tentacle account that is running the Octopus Tentacle service has access to that folder.

We have a malware page here which details what folders Octopus uses so those are the ones your Tentacle service account needs access to (minus the C:\Octopus\OctopusServer\Tools* as that is just for Octopus Server not Tentacle).

Can you also ensure those folders in that documentation I linked are whitelisted in your Antivirus definitions.

When you ran the commands using PowerShell were you running them from the Tentacle service account (ie logged in as the tentacle service account) or another account that has admin rights to that server?

I look forward to hearing if any of those suggestions work, if not we can dig a bit further for you,
Kind Regards,
Clare

1 Like

Hi Clare - thank you! Giving teh correct permissions to the work folder on the C Drive helped resolve the issue!

Hey @JCollier,

Great news that solved the issue for you, thank you for letting me know, reach out in future if you need any further assistance as we are always on hand to help!

Kind Regards and Happy Deployments,
Clare

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