Error MSB4018: The "MakeUniqueDir" task failed unexpectedly

Azure DevOps Service
SonarQube Extension version 5.8.1
SonarScanner for MSBuild 5.8

Error MSB4018: The "MakeUniqueDir" task failed unexpectedly.
System.UnauthorizedAccessException: Access to the path 'DDevOpsAgentsBUILD-SIM-2_work8.sonarqubeout' is denied.
   at System.Threading.Mutex.CreateMutexCore(Boolean initiallyOwned, String name, Boolean& createdNew)
   at SonarScanner.MSBuild.Common.UniqueDirectory.CreateNext(String path)
   at SonarScanner.MSBuild.Tasks.MakeUniqueDir.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
D:\DevOps\Agents\BUILD-SIM-2\_work\8\.sonarqube\bin\targets\SonarQube.Integration.targets(313,5): error MSB4018: The "MakeUniqueDir" task failed unexpectedly. [D:\DevOps\Agents\BUILD-SIM-2\_work\8\s\Source\OutboundArea\OutboundArea.csproj]
D:\DevOps\Agents\BUILD-SIM-2\_work\8\.sonarqube\bin\targets\SonarQube.Integration.targets(313,5): error MSB4018: System.UnauthorizedAccessException: Access to the path 'DDevOpsAgentsBUILD-SIM-2_work8.sonarqubeout' is denied. [D:\DevOps\Agents\BUILD-SIM-2\_work\8\s\Source\OutboundArea\OutboundArea.csproj]
D:\DevOps\Agents\BUILD-SIM-2\_work\8\.sonarqube\bin\targets\SonarQube.Integration.targets(313,5): error MSB4018:    at System.Threading.Mutex.CreateMutexCore(Boolean initiallyOwned, String name, Boolean& createdNew) [D:\DevOps\Agents\BUILD-SIM-2\_work\8\s\Source\OutboundArea\OutboundArea.csproj]
D:\DevOps\Agents\BUILD-SIM-2\_work\8\.sonarqube\bin\targets\SonarQube.Integration.targets(313,5): error MSB4018:    at SonarScanner.MSBuild.Common.UniqueDirectory.CreateNext(String path) [D:\DevOps\Agents\BUILD-SIM-2\_work\8\s\Source\OutboundArea\OutboundArea.csproj]
D:\DevOps\Agents\BUILD-SIM-2\_work\8\.sonarqube\bin\targets\SonarQube.Integration.targets(313,5): error MSB4018:    at SonarScanner.MSBuild.Tasks.MakeUniqueDir.Execute() [D:\DevOps\Agents\BUILD-SIM-2\_work\8\s\Source\OutboundArea\OutboundArea.csproj]
D:\DevOps\Agents\BUILD-SIM-2\_work\8\.sonarqube\bin\targets\SonarQube.Integration.targets(313,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [D:\DevOps\Agents\BUILD-SIM-2\_work\8\s\Source\OutboundArea\OutboundArea.csproj]
D:\DevOps\Agents\BUILD-SIM-2\_work\8\.sonarqube\bin\targets\SonarQube.Integration.targets(313,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [D:\DevOps\Agents\BUILD-SIM-2\_work\8\s\Source\OutboundArea\OutboundArea.csproj]

We have installed four self-hosted agents across one physical-box.
The issue occurs usually when you run two pipelines in parallel on different agents.
Both of them are doing SonarQube analysis.

1 Like

Hi,

Welcome to the community!

Can you confirm that the account running analysis has full permissions, recursive, to the project/analysis directory?

 
Ann

Hi,
Thank you for your reply.
Yes, I can confirm that.
If the pipeline is run alone all is fine (permission are there/access ok), the issue occurs only in case simultaneously run of two different pipelines.

We are also having this issue, on many pipeline runs.
We also have 4 self-hosted agents on one Windows server.
SonarQube for MSBuild 5.8.1
SonarScanner on agents 4.7.0.2747

It doesn’t seem to occur when we let only 1 agent run the pipelines, but this is not a good solution for us. We run many pipelines and need to be able to let them run parallel.
This start to be an issue last week, before Sonarcloud was able to work with parallel pipelines.

The agent has full access on the folder (and underlying folders).
Is there a way to fix this and run parallel pipelines?

Error:

D:\AgentBUILD08-01\_work\2474\.sonarqube\bin\targets\SonarQube.Integration.targets(313,5): error MSB4018: The "MakeUniqueDir" task failed unexpectedly. [D:\AgentBUILD08-01\_work\2474\s\src\.csproj]
D:\AgentBUILD08-01\_work\2474\.sonarqube\bin\targets\SonarQube.Integration.targets(313,5): error MSB4018: System.UnauthorizedAccessException: Access to the path 'DAgentBUILD08-01_work2474.sonarqubeout' is denied. [D:\AgentBUILD08-01\_work\2474\s\src\.csproj]
D:\AgentBUILD08-01\_work\2474\.sonarqube\bin\targets\SonarQube.Integration.targets(313,5): error MSB4018:    at System.Threading.Mutex.CreateMutexCore(Boolean initiallyOwned, String name, Boolean& createdNew) [D:\AgentBUILD08-01\_work\2474\s\src\.csproj]
D:\AgentBUILD08-01\_work\2474\.sonarqube\bin\targets\SonarQube.Integration.targets(313,5): error MSB4018:    at SonarScanner.MSBuild.Common.UniqueDirectory.CreateNext(String path) [D:\AgentBUILD08-01\_work\2474\s\src\.csproj]
D:\AgentBUILD08-01\_work\2474\.sonarqube\bin\targets\SonarQube.Integration.targets(313,5): error MSB4018:    at SonarScanner.MSBuild.Tasks.MakeUniqueDir.Execute() [D:\AgentBUILD08-01\_work\2474\s\src\.csproj]
D:\AgentBUILD08-01\_work\2474\.sonarqube\bin\targets\SonarQube.Integration.targets(313,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [D:\AgentBUILD08-01\_work\2474\s\src\.csproj]
D:\AgentBUILD08-01\_work\2474\.sonarqube\bin\targets\SonarQube.Integration.targets(313,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [D:\AgentBUILD08-01\_work\2474\s\src\.Service.csproj]
1 Like

@Maciej77154671

Hello, could you please tell us if you are running the analysis build in parallel and if you are running them with the same user?

All the best,
Čaba

Hi Caba,

For us this problem occurs when we run two build pipelines simultanously, so in parallel, on the same server. It does run on two different agents, but they use the same (windows/ad) user. The build pipelines can be two different projects, so it does not seem like they use the same files.

1 Like

Same here,
Running multiple agents on one Windows server. All agents run with the Network Service account. Both builds run on different agents simultaneously (building different parts of a mono repo).

Running the builds separately ‘solves’ the problem, but slows down the build process way to much

1 Like

@Caba_Sagi can you give an update on this issue?

1 Like

hello,
We are also having this issue, on many pipeline runs. We have agents(Agent.Version 2.213.2) on one Windows server. We run many pipelines and need to be able to let them run parallel. Is there any update about this topic ? This issue is very critical for us. Please update us ASAP. Please urgently.

|Agent.Version|2.213.2|||
||Agent.OS|Windows_NT||
||Agent.OSArchitecture|X64||
||Agent.OSVersion|10.0.14393||

@mkapar, @nv010, @Maciej77154671 and @jhoek

I am unable to reproduce the issue, to be able to continue with further investigation I would need your help.
Could you please provide me with some further information?

  • What operating system are you using?
  • And what .net runtime are you using to build your project?
  • Are your build agents running under the NETWORK SERVICE account? If so, could you try running them under a “normal” user account to see if the issue still occurs please?

Many thanks in advance!

Best,
Čaba

Actually, @duncanp managed to reproduce the problem and reported the issue in our github repository.

1 Like

We solved this issue for our setup by setting the environment variable MSBUILDDISABLENODEREUSE=1 on the affected servers.

In the SonarCloud documentation this is mentioned as the /nr:false argument. The MSBUILD docs mentioned the environment variable we ended up using.

Hope this helps some of you as well.

2 Likes