0
votes

I want to copy build artifacts from $(System.ArtifactsDirectory) to shared folder on remote Windows Server 2016. I am using "Windows Machine File Copy" task for this. It works when I use this-

- task: WindowsMachineFileCopy@2
displayName: 'Copy build artifacts'
inputs:
  SourcePath: '$(System.ArtifactsDirectory)/*'
  MachineNames: 'targetHostname'
  AdminUserName: 'domain\administrator'
  AdminPassword: '******'
  TargetPath: 'D:\sharedfolder'

But I do not want to use admin credentials that you see above. I read MS doco- https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/windows-machine-file-copy?view=azure-devops

Admin credential parameters AdminUserName and AdminPassword are optional. But I remove them copy task fails. So my requirement is- we do not want to use username and password. Instead we want to use Azure Service Principal. Is there a way I can achieve copying files using Service Principal instead of username and password?

1

1 Answers

0
votes

So my question is- how do I copy files without using any credentials?

If you want copy files without using any credentials, that means you need to set the permissions of your target folder that anyone can access.

Obviously this is unsafe, we do not recommend you to do this. If you have a reason to insist on doing this and you can ensure information security, you can refer to the following way.

You could share the folder to everyone in the remote machine:

enter image description here

Then, we could just use the copy task to to copy build artifacts from $(System.ArtifactsDirectory) to shared folder on remote Windows Server 2016:

enter image description here

I test it with remote Windows Server 2012, and it works fine.

Hope this helps.