6

I am building a Release Pipeline on Azure DevOps. Part of my release is to copy a bunch of files to the Azure VM. As far as I understand, the target machine needs to have PowerShell 5986 port open.

I have a VM with port 5986 open (I verified that by invoking remotely some commands on this VM with "PowerShell on Target Machines" task). I added "Windows Machine File Copy" task and filled fields: - Source - Machines - Admin Login - Password - Destination Folder

In "Machines" field, I put IP of the target machine.

As a result of running the release, I'm getting an error:

Failed to Create PSDrive with Destination: '\\11.11.11.11\C$\TargetDirectory', ErrorMessage: 'The network path was not found' The network path was not found

I also tried to put IP address with a port, in this form: 11.11.11.11:5986

Then, I got this error:

Cannot convert value "\23.97.151.221:5986" to type "System.Uri". Error: "Invalid URI: The hostname could not be parsed."

Documentation (https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/windows-machine-file-copy?view=azure-devops) says that IP address with a port is allowed.

What's the issue here?

mnj
  • 2,539
  • 3
  • 29
  • 58
  • Try to put the machine hostname instead of the IP – Shayki Abramczyk Jun 05 '19 at 11:57
  • does `Get-ChildItem -Path ''\\11.11.11.11\C$'` give you any response? note that this is NOT using any powershell port ... the port you refer to is the WinRM over HTTPS port, and is not used for UNC filesystem access. – Lee_Dailey Jun 05 '19 at 12:01
  • @ShaykiAbramczyk My target VM does not have any DNS name, it's also not in any Domain. – mnj Jun 05 '19 at 12:17
  • @Lee_Dailey From where should I invoke this command? – mnj Jun 05 '19 at 12:18
  • @Loreno - where you are running your code. [*grin*] just put it in the script just before your current drive map line and save it somewhere so you can look at it. – Lee_Dailey Jun 05 '19 at 12:25
  • @Lee_Dailey I tried that on my target VM (I logged in there through RDP): Get-ChildItem -Path '\\11.11.11.11\C$' - I got "Cannot find path '\\11.11.11.11\C$' because it does not exist". I also tried Get-ChildItem -Path '\\localhost\C$' which worked. (Of course "11.11.11.11" represents the public IP of my target VM in these examples) – mnj Jun 06 '19 at 07:13
  • @Loreno - i can't test this - no cloud access - but you need to find the correct syntax _for your environment_. if you cannot use the usual powershell commands to access the destination then you are likely looking at a permission problem. – Lee_Dailey Jun 06 '19 at 23:45

6 Answers6

10

I was getting the exact same error while doing these:

  • Initially in my release pipeline, I had an agent job and I created a Windows machine file copy task under the job and filled in all details correctly. I set the Machines field with the public IP address of my target server (a Windows azure VM) and I always got this error you reported.

  • I tried to use the Azure file copy task instead but I was faced with another problem (error message: Unable to get FQDN for all resources in ResourceGroup: {resourceGroupName}) which I couldn't get to fix after a lot of efforts.

This is the solution that worked for me:

  • Instead of running an agent job, I ran a Deployment Group Job. With deployment groups, I didn't need an IP address to connect to my VM. Setting up a deployment group for your Azure VM is very simple and well explained here

  • I created a Windows Machine File Copy task under the Deployment Group job I added. I filled same details for the task except that instead of the IP address of the Windows VM, I entered the computer name in the Machines field and the file copy task ran successfully!

I hope this helps

Yusuff Sodiq
  • 815
  • 2
  • 12
  • 19
  • Deployment group has to be manually created after creating a VM? if yes then automation is not possible with this approach. eg: A release pipeline to create CM , then copy files, then install. – Blue Clouds Feb 06 '20 at 09:44
  • for the computer name did you use a variable, since each deployment target in the group would have a different name? If so was it a standard variable? – Mido Mar 23 '20 at 15:37
  • @Mido yes I used a variable and I specified it as something like $(vmComputerName). I set the value for it in the variables tab. – Yusuff Sodiq Apr 15 '20 at 04:24
  • Hi, I follow your step, however, it works only on some of my VMs. The messages show {Failed to Create PSDrive with Destination: '\\MACHINE_NAME\D$', ErrorMessage: 'Access is denied'} Any suggestions? – han shih Jun 08 '22 at 04:18
  • @hanshih Make sure the Service Account that is configured with the task (i.e. Admin Login) has permissions on the destination folder of each target machine. – Steve Aug 04 '22 at 19:32
9

The problem is because you can't use that task to copy files across Windows Domain boundary! That is to say, if you build on host A and want to copy files to host B, then A and B must be in the same Windows Domain, otherwise you'll get the error like

##[error]Failed to Create PSDrive with Destination: '\\your-server-name-or-ip\some\path', ErrorMessage: 'The network path was not found'

That is to say, if you're using a hosted agent, then you're not able to copy files with that task to any host you have, no matter it has a public IP or not, or a FQDN, because they are not in the same Windows Domain!

You have two options to work around it:

  • Use Azure File Copy task if your target is an Azure VM or Azure Storage
  • Use private hosted agent and make sure your target host and your private agent are in the same Windows Domain

Last but not least, the document should really make it clear! It wasted me a lot of time on solving the problem!

Robert
  • 1,964
  • 1
  • 22
  • 22
2

go to the destination folder, right-click the folder select properties,share option is there, click that one and share everyone option is there

Neeraj
  • 749
  • 6
  • 15
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Neeraj Nov 19 '21 at 07:10
0

I solved it! You must use "down level user name" under "Admin Login": domain/username

Hier is "domain" from User account, not Web-domain ;)

And now you can copy files across Windows Domain boundary :)

Good luck!

PaAl
  • 1
  • 1
  • Can you explain how this can address the question? Also, please read [how to answer](https://stackoverflow.com/help/how-to-answer) – pierpy May 21 '23 at 08:34
-2

The solution is to go to the target server and SHARE the directory where the files would be copied. In Windows, just go to Properties of the directory, Sharing tab, and Share it to the user which is used in the VSTS task.

mnj
  • 2,539
  • 3
  • 29
  • 58
-4

The answer is pretty simple, the DevOps Tasks are actually running PowerShell on you VM and trying to create a PSDrive.

Try using the task mentioned in the screenshot below:

double-beep
  • 5,031
  • 17
  • 33
  • 41
Vikas Goyal
  • 342
  • 2
  • 10
  • The question it's about **this** task. how you solve the issue?! – Shayki Abramczyk Jun 06 '19 at 06:32
  • Hi Loreno, I feel there are some issues the way you have exposed your storage to the internet. There are some firewall issues, otherwise it works very fine. – Vikas Goyal Jun 06 '19 at 07:54
  • Can you please verify that apart from Azure DevOps, are you able to access your File location from your Desktop? – Vikas Goyal Jun 06 '19 at 07:55
  • @VikasGoyal My target VM is a machine in Azure. In its NSG (so, firewall) RDP port and 5986 port are open – mnj Jun 06 '19 at 10:29
  • Try this and let me know if you are able to do it from your Desktop or not... If it is available then only Azure will be able to access it.. other wise it as good as not available https://www.google.com/amp/s/www.faqforge.com/windows/create-powershell-session-remote-computer/amp/ – Vikas Goyal Jun 06 '19 at 10:32
  • @VikasGoyal PowerShell Remoting works with this VM, I tried that. Even in my Pipeline I have a "PowerShell on Target Machines" task that executes some commands there - and it works successfully – mnj Jun 06 '19 at 10:34
  • I got the issue now, your machine is exposed only on RDP port and the plugin is trying to access is through other one.. – Vikas Goyal Jun 06 '19 at 10:38
  • I have the solution for this one.. but can not share the steps here, need to look at the azure portal of the VM. – Vikas Goyal Jun 06 '19 at 10:39
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/194535/discussion-between-vikas-goyal-and-loreno). – Vikas Goyal Jun 06 '19 at 11:00