Permissions issue when running pre deploy powershell

Hello,
I am getting the following error when I am trying to deploy a windows service. I have a pre-deployment and post deployment script that are run but the pre-deployment one is erroring out due to permissions. I have granted the local service account for the tentacle permissions to the directory that it is deploying to as well as the octopus folder where the configuration files are and still no dice.

Did not overwrite ‘C:\Services\TaskEngine\Octopus.Features.WindowsService_BeforePostDeploy.ps1’, it was already on disk
10:41:14Error
System.UnauthorizedAccessException: Access to the path ‘C:\Services\TaskEngine\Bootstrap.Octopus.Features.WindowsService_BeforePostDeploy.ps1’ is denied.
10:41:14Error
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
10:41:14Error
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
10:41:14Error
at System.IO.FileStream…ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
10:41:14Error
at System.IO.StreamWriter…ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost)
10:41:14Error
at System.IO.StreamWriter…ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
10:41:14Error
at System.IO.StreamWriter…ctor(String path, Boolean append, Encoding encoding)
10:41:14Error
at Calamari.Integration.Scripting.WindowsPowerShell.PowerShellBootstrapper.PrepareBootstrapFile(String targetScriptFile, VariableDictionary variables) in y:\work\b1fd300731d5f2fc\source\Calamari\Integration\Scripting\WindowsPowerShell\PowerShellBootstrapper.cs:line 68
10:41:14Error
at Calamari.Integration.Scripting.WindowsPowerShell.PowerShellScriptEngine.Execute(String scriptFile, VariableDictionary variables, ICommandLineRunner commandLineRunner) in y:\work\b1fd300731d5f2fc\source\Calamari\Integration\Scripting\WindowsPowerShell\PowerShellScriptEngine.cs:line 20
10:41:14Error
at Calamari.Integration.Scripting.CombinedScriptEngine.Execute(String scriptFile, VariableDictionary variables, ICommandLineRunner commandLineRunner) in y:\work\b1fd300731d5f2fc\source\Calamari\Integration\Scripting\CombinedScriptEngine.cs:line 46
10:41:14Error
at Calamari.Deployment.Conventions.FeatureScriptConvention.Install(RunningDeployment deployment) in y:\work\b1fd300731d5f2fc\source\Calamari\Deployment\Conventions\FeatureScriptConvention.cs:line 66
10:41:14Error
at Calamari.Deployment.ConventionProcessor.RunInstallConventions() in y:\work\b1fd300731d5f2fc\source\Calamari\Deployment\ConventionProcessor.cs:line 60
10:41:14Error
at Calamari.Deployment.ConventionProcessor.RunConventions() in y:\work\b1fd300731d5f2fc\source\Calamari\Deployment\ConventionProcessor.cs:line 28
10:41:14Error
Running rollback conventions…
10:41:14Error
System.UnauthorizedAccessException: Access to the path ‘C:\Services\TaskEngine\Bootstrap.Octopus.Features.WindowsService_BeforePostDeploy.ps1’ is denied.
10:41:14Error
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
10:41:14Error
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
10:41:14Error
at System.IO.FileStream…ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
10:41:14Error
at System.IO.StreamWriter…ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost)
10:41:14Error
at System.IO.StreamWriter…ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
10:41:14Error
at System.IO.StreamWriter…ctor(String path, Boolean append, Encoding encoding)
10:41:14Error
at Calamari.Integration.Scripting.WindowsPowerShell.PowerShellBootstrapper.PrepareBootstrapFile(String targetScriptFile, VariableDictionary variables) in y:\work\b1fd300731d5f2fc\source\Calamari\Integration\Scripting\WindowsPowerShell\PowerShellBootstrapper.cs:line 68
10:41:14Error
at Calamari.Integration.Scripting.WindowsPowerShell.PowerShellScriptEngine.Execute(String scriptFile, VariableDictionary variables, ICommandLineRunner commandLineRunner) in y:\work\b1fd300731d5f2fc\source\Calamari\Integration\Scripting\WindowsPowerShell\PowerShellScriptEngine.cs:line 20
10:41:14Error
at Calamari.Integration.Scripting.CombinedScriptEngine.Execute(String scriptFile, VariableDictionary variables, ICommandLineRunner commandLineRunner) in y:\work\b1fd300731d5f2fc\source\Calamari\Integration\Scripting\CombinedScriptEngine.cs:line 46
10:41:14Error
at Calamari.Deployment.Conventions.FeatureScriptConvention.Install(RunningDeployment deployment) in y:\work\b1fd300731d5f2fc\source\Calamari\Deployment\Conventions\FeatureScriptConvention.cs:line 66
10:41:14Error
at Calamari.Deployment.ConventionProcessor.RunInstallConventions() in y:\work\b1fd300731d5f2fc\source\Calamari\Deployment\ConventionProcessor.cs:line 60
10:41:14Error
at Calamari.Deployment.ConventionProcessor.RunConventions() in y:\work\b1fd300731d5f2fc\source\Calamari\Deployment\ConventionProcessor.cs:line 50
10:41:14Error
at Calamari.Commands.DeployPackageCommand.Execute(String[] commandLineArguments) in y:\work\b1fd300731d5f2fc\source\Calamari\Commands\DeployPackageCommand.cs:line 107
10:41:14Error
at Calamari.Program.Main(String[] args) in y:\work\b1fd300731d5f2fc\source\Calamari\Program.cs:line 21

Hi Cbartlett,
The scripts don’t get written to disk if they already exist, hence the Did not overwrite ..., it was already on disk error message. If it already exists though its odd that its complaining that it doesn’t have access to that file. Can you try log in and manually delete that file before running the task again. I’m wondering if it was previously created with some other credentials that the current user account no longer has access to.
Let me know if this allows the script to execute.
Cheers,
Robert

I have also - "System.UnauthorizedAccessException: Access to the path ‘C:\DFS_Deployments\UniversalWorker\Bootstrap.Octopus.Features.WindowsService_BeforePostDeploy.ps1’ is denied. …"
manually delete that file before running the task again - didn’t help. Have any more solutions for this case ?

Hi Denchyk,
Could you confirm that you also don’t have some sort of virus protection which is causing problems with writing this file. The error does explicitly complain about permissions so I’m not sure what else could be the cause. Perhaps download and take look at process monitor to see what, if anything is trying to access that file.
Cheers,
Robert

Hi,
Thanks for quick response.
I don’t have this problem any more - It sorted
Cheers
denchyk

I changed how I was doing things. I now have my scripts directly in the step instead of using a script module. This works every time and is much easier to maintain for an individual deployment.

Thanks!

Hi,
That’s great to hear you have everything running smoothly again.
Thanks for the update.
Cheers,
Robert

This discussion saved my day. Thanks