Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Pipelines: Accessing network drives on self-hosted Windows agent?

I have a local Windows machine with a self-hosted Azure Pipeline agent on which I want to run some scripts that require access to files stored on network drives. However, they don't seem to be accessible as I get "Path not found" or similar errors. Running net use in Powershell does return a list of the network drives I want to access, but their status are set to "Unavailable".

I suspect this has something to do with authentication, but I'm not sure how to solve that. I should note that I do not have administrator permissions, but my user does have access to the drives normally and the agent is configured using my username.

like image 544
Wiktor Gustafsson Avatar asked Oct 21 '25 18:10

Wiktor Gustafsson


1 Answers

Azure Pipelines: Accessing network drives on self-hosted Windows agent?

When you execute the build, all build tasks should run under your build service account such as AzuredevopsAccount1.

So, you need make sure if the build service account has permission to access network drives.

Besides, if you have username and password to access the network drives, we could try to use it to to access the network drives.

For example, I use powershell scripts to copy the sources files with the specific username and password provided to the network drives:

$Source = $env:BUILD_SOURCESDIRECTORY
$Dest   = "\\172.17.xx.xx\SourceFiles\xxx"
$Username = "domain\username"
$Password = ConvertTo-SecureString "PasswordHere" -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential($Username, $Password)
New-PSDrive -Name J -PSProvider FileSystem -Root $Dest -Credential $mycreds -Persist
Copy-Item -Path $Source -Recurse -Force -Destination $Dest 

The test result:

enter image description here

Hope this helps.

like image 82
Leo Liu-MSFT Avatar answered Oct 25 '25 00:10

Leo Liu-MSFT