Prepare Analysis on Azure DevOps failing with an access exception

Our Azure DevOps build is failing when calling the Prepare Analysis on Sonar Cloud step. The process we are following, using a Windows 2019 Microsoft hosted agent is as follows;
image

Within the prepare analysis on Sonar Cloud step we get the following sequence of events with error;

2023-03-30T16:48:55.4371543Z ==============================================================================
2023-03-30T16:48:55.4371718Z Task         : Prepare Analysis Configuration
2023-03-30T16:48:55.4371824Z Description  : Prepare SonarCloud analysis configuration
2023-03-30T16:48:55.4371928Z Version      : 1.34.0
2023-03-30T16:48:55.4371996Z Author       : sonarsource
2023-03-30T16:48:55.4372121Z Help         : Version: 1.34.0. [More Information](https://docs.sonarcloud.io/advanced-setup/ci-based-analysis/sonarcloud-extension-for-azure-devops/)
2023-03-30T16:48:55.4372317Z ==============================================================================
2023-03-30T16:48:56.7135805Z [command]D:\a\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.34.0\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe begin /k:iPSLAz_AGY_Web /o:ipsl-sonarcloudkey-devops-lspi
2023-03-30T16:48:56.8486346Z SonarScanner for MSBuild 5.12
2023-03-30T16:48:56.8487739Z Using the .NET Framework version of the Scanner for MSBuild
2023-03-30T16:48:56.8692625Z Pre-processing started.
2023-03-30T16:48:56.8720243Z Preparing working directories...
2023-03-30T16:48:56.9554909Z 16:48:56.954  Updating build integration targets...
2023-03-30T16:48:57.1105728Z 16:48:57.104  Fetching analysis configuration settings...
2023-03-30T16:48:57.5332844Z 16:48:57.527  Provisioning analyzer assemblies for cs...
2023-03-30T16:48:57.5343537Z 16:48:57.527  Installing required Roslyn analyzers...
2023-03-30T16:48:58.1660658Z 16:48:58.158  Provisioning analyzer assemblies for vbnet...
2023-03-30T16:48:58.1661408Z 16:48:58.158  Installing required Roslyn analyzers...
2023-03-30T16:48:58.2237687Z 16:48:58.218  Downloading cache. Project key: iPSLAz_AGY_Web, branch: main.
2023-03-30T16:48:59.6445361Z 
2023-03-30T16:48:59.6446601Z ##[error]Unhandled Exception:
2023-03-30T16:48:59.7147517Z ##[error]System.UnauthorizedAccessException: Access to the path 'D:\a\1\s\AGY\Web\Source\iPSL.AP.Web\iPSL.AP.Web.Proxy.UnitTests\Properties\AssemblyInfo.cs' 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, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode)
   at SonarScanner.MSBuild.PreProcessor.CacheProcessor.ContentHash(String path)
   at SonarScanner.MSBuild.PreProcessor.CacheProcessor.<>c__DisplayClass15_0.<ProcessPullRequest>b__2(<>f__AnonymousType0`2 x)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at SonarScanner.MSBuild.PreProcessor.CacheProcessor.ProcessPullRequest(IList`1 cache)
   at SonarScanner.MSBuild.PreProcessor.CacheProcessor.<Execute>d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at SonarScanner.MSBuild.PreProcessor.PreProcessor.<DoExecute>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at SonarScanner.MSBuild.PreProcessor.PreProcessor.<Execute>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at SonarScanner.MSBuild.BootstrapperClass.<PreProcess>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at SonarScanner.MSBuild.BootstrapperClass.<Execute>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at SonarScanner.MSBuild.Program.<Execute>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at SonarScanner.MSBuild.Program.<Execute>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at SonarScanner.MSBuild.Program.<Main>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at SonarScanner.MSBuild.Program.<Main>(String[] args)

This error is only occuring when triggering the build from within a feature branch to our MAIN branch. We can run all of the build steps with no problem directly on our main or feature branch, and pulling between two feature branches does not cause a problem.

Is the source code cached somewhere when building within a pull request and how could we clear that cache?
We’re unable to navigate to D:\a\1\s\AGY\Web\Source\iPSL.AP.Web\iPSL.AP.Web.Proxy.UnitTests\Properties\AssemblyInfo.cs as that will be a location in the Microsoft Hosted build agent.

Has anyone seen this type of issue before? Any suggestions?

Hi,

This looks like a permissions problem. Off hand, two possibilities spring to mind:

  • the user account running the build analysis doesn’t have full, recursive permissions
  • you have something “helpful” running on the build agent (like a virus scanner) that’s interfering

You say this only happens for branches. Is it always on the same file? Does it happen every time?

 
Ann