Reputation: 8295
I have setup a VM Scale Set and configured it with Azure DevOps as an agent pool.
In order to prevent nuget packages being re-downloaded on every build, I have created a File Share with a storage account, and added a script extension to the scale set to mount the file share as drive Z when the VMs are created.
I've updated my NuGetCommand@2
as follows:
- task: NuGetCommand@2
displayName: 'Restore Packages'
inputs:
restoreSolution: '**/*.sln'
restoreDirectory: 'Z:\NuGetCache'
But this now fails with the error:
##[error]The nuget command failed with exit code(1) and error(The user name or password is incorrect.
There are no private nuget sources used that require authentication, so I suspect the issue is perhaps the account that the agent runs under doesn't have access to the file share / mounted drive. But I don't know what the account name would be or how to grant access?
Upvotes: 0
Views: 103
Reputation: 4957
I can reproduce the issue when the image of my VMSS is WindowsServer.
After investigation, I found the reason was that the custom script extension did not successfully connect the instance to the Azure file share. When I remote to the instance, I can see this:
For further investigation, I manually run the scripts (copied from file share connection page) used to connect to Azure file share, then the instance can connect to the file share successfully. However, the pipeline still can't access the file share.
According to Lifecycle of a Scale Set Agent,
The configuration script creates a local user named
AzDevOps
if the operating system is Windows Server or Linux.
And this account has been added into the Administrators group. I don't understand why the local account created from VMSS which is also Administrator can access it but AzDevOps
can't. However, if the custom scripts are run by AzDevOps
, then the pipeline can access the file share. You can use it as a workaround.
Workarounds:
Workaround1: Don't use the custom script extension in VMSS to mount the file share and run the scripts directly in the pipeline. For example,
# Add azure file share to the instance
- task: PowerShell@2
inputs:
filePath: 'fileshare.ps1'
- task: NuGetCommand@2
inputs:
command: 'restore'
restoreSolution: 'mockagent/mockagent.sln'
restoreDirectory: 'Z:\nuget'
Result:
Workaround2: Use custom image.
According to Create a scale set with custom image, software, or disk size,
To customize the permissions of the pipeline agent user, you can create a user named
AzDevOps
, and grant that user the permissions you require. This user will be created by the scaleset agent startup script if it doesn't already exist.
In the image, create AzDevOps
account manually and use it to connect to Azure file share.
Upvotes: 0