UnauthorizedAccessException using octo.exe create-release

Getting this error when calling Octo with the following parameters:

octo.exe create-release --server http://server --apikey blahblahblah --project "Release" --enableservicemessages --channel MyChannel

System.UnauthorizedAccessException: Access to the path 'C:\ProgramData\chocolatey\lib\OctopusTools\tools\9a08374b-40a7-4
d63-a5d2-c7d9c1f12941.md' is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShar
e share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolea
n useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileO
ptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.StreamWriter.CreateFile(String path, Boolean append, Boolean checkHost)
   at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost)
   at System.IO.File.InternalWriteAllText(String path, String contents, Encoding encoding, Boolean checkHost)
   at System.IO.File.WriteAllText(String path, String contents)
   at Octopus.Cli.Diagnostics.LogExtensions.TfsServiceMessage(ILogger log, String serverBaseUrl, ProjectResource project
, ReleaseResource release)
   at Octopus.Cli.Commands.CreateReleaseCommand.<Execute>d__31.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Octopus.Cli.Commands.ApiCommand.<Execute>d__31.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Octopus.Cli.Program.Run(String[] args)

David

Hi David,

Thank you for getting in touch. Are you running this locally, during a TFS build or another build system?

The --enableservicemessages flag writes out a file designed for TFS to consume. It writes the file to the directory specified by the SYSTEM_DEFAULTWORKINGDIRECTORY environment variable, or the exe directory if that variable does not exist. I think the latter is occuring, and the user running the command does not have permission to write to that directory. If you do want the service message file output, please set the SYSTEM_DEFAULTWORKINGDIRECTORY variable, otherwise remove the --enableservicemessages flag. For more detail on what it does see the code here.

Hope that helps.

Robert W

I was just running this from the command line, but it was originally copied
from my TeamCity build log.

I’d suggest that defaulting to the .exe’s directory may not be the best
choice - especially if it is installed in a protected location. Wouldn’t
defaulting to the current directory, or if the file is temporary the %TEMP%
directory be better options?

David

Hi David,

Thank you for the suggestion. I’m not totally familiar with TFS, but I believe the service message file needs to be somewhere in the working directory structure to be picked up. Octo.exe on a build server is commonly copied to the working directory, so the fallback makes sense. Other than chocolatey, octo.exe does not have an installer.

I have however improved the error message.

Robert W