Sep 26 2024 10:48 PM
Hello,
I'm experiencing an issue with our Azure DevOps pipeline running on a self-hosted agent. During the initial execution, the pipeline fails with the following error message:
System.UnauthorizedAccessException: Access to the path 'D:\path\to\file.dll' is denied.
The error occurs during built-in tasks like Initialize Job and Checkout. However, when I retrigger the pipeline, it passes successfully.
Details:
Questions:
Any guidance or recommendations to resolve this issue would be greatly appreciated.
Environment Details:
Sep 28 2024 11:18 AM
These steps should help prevent the access issue from recurring.
The error happens on the first run because the DLL might be locked by another process. By the time you retrigger the pipeline, that process has released the lock, allowing the second attempt to succeed.
Yes, it’s probably due to file locks. The self-hosted agent may be trying to access the DLL while another application is still using it. Background processes, including explorer.exe, could also interfere.
To avoid this issue:
Add Retry Logic: Implement retries in your pipeline if it encounters a lock.
Pre-Execution Check: Check if the DLL is locked before running tasks. If it is, wait a moment and try again.
Optimize Agent Setup: Ensure the agent runs under a dedicated user with proper permissions.
Identify Locking Processes: Use tools like Process Explorer to find what’s locking the DLL.
Reference URL:
- https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/v2-windows?view=azure-devops
- CreateFileA function (fileapi.h) - Win32 apps | Microsoft Learn