Copy File from one server t another server

modelling

#1

Hi,
I have one requirement to copy file from from one server to another using octopus deploy. But am unable to copy because the both servers are running in a different account and there is no access to create any shared folders on to the servers. I heard this could be possible do with octopus artifacts.
Please provide a suggestion or help to get it done with octopus artifact.
I tried the below step in octopus deploy
New-OctopusArtifact -Path “D:\APPS\Mysite\File.xml” -Name “$([System.Environment]::\secondservername\D$)-File.xml”
this step i executed from my first server.

Please provide a best way to copy file from my first server to second server.


(Kenneth Bates) #3

Hi,

Thanks for getting in touch! Using the New-OctopusArtifact CmdLet will copy an existing file on your target to the Octopus Server. While there’s no way I can think of to send that file to another target as is, there are still a few potential options.

  • Are you able to copy the file manually? You could theoretically script the copy and add it as a script step in your deployment process.
  • You could read the file from a script, encode it into base64 and create an output variable with this value. Using a script step, you could create the file on the target with the value from this output variable.
  • You could also add the file to the package you’re deploying.

Would one of these options help you achieve what you’re after? Let me know how you go or if you have any further questions going forward. :slight_smile:

Kind regards,

Kenny


#4

Hi Kenny,

Thanks for your reply.

Actual my requirement is

  1. I have to generate one key file in server1 - i done this successfully using script step.

  2. I need to copy the generated key file into server2 with out generating new one - I tried using Copy-Item cmdlet but i failed because of access permission.
    Query used: “Copy-Item -Path \Server1\D$\Test_multiple_file\Test_1.txt -Destination D:\Test_multiple_file –Recurse” query executed as script step in server2.

  3. I tried using New-OctopusArtifact CmdLet to collect the key file after executing the point 1 - Artifact is getting available for download

  4. Now i need a help to move the collected artifact(Key file generated from server1) to server2.

Please help me to achieve this.

Thanks,
Rajakulai


(Kenneth Bates) #5

HI Rajakulai,

Thanks for following up! Unfortunately I’m unable to think of an approach that would collect the artifact from the Octopus Server and deploy it to the second server within the same deployment process. I think the only option may be to use the second option I mentioned above. After generating the file on server1, use another script step to read it and create an output variable with the contents as the value. On another step that targets only sever2, create the file with the value of that output variable.

I hope this helps!

Best regards,

Kenny


#6

Hi Kenny,

Thanks for your reply.

I tried Reading a file and creating an Output Variable from server 1 using below script
$File = Get-Content -Path "D:\Backup\Web.Config
Set-OctopusVariable -name “TestMovingFileToServer” -value $File
I created another step for server 2 to creating a file with output variable, But i got an error. Script used:
$FileToMove = $OctopusParameters[“Octopus.Action[Test1].Output.TestMovingFileToServer”]
New-Item $FileToMove -ItemType file
Error I Received:
New-Item : Cannot bind argument to parameter ‘Path’ because it is null.
At C:\Octopus\Work\20180710071432-1259\Script.ps1:4 char:10
New-Item $FileToMove -ItemType file

Please help me to execute the correct script which i missed anything.

Thanks,
Rajakulai


#7

Hi Kenny,

I get it done the script corrected. And now am able to create the file in server 2 with output variable.
Thank you very much for guiding me the best approach to get my requirement done. :slight_smile:

Thanks,
Rajakulai


(Kenneth Bates) #8

Hi Rajakulai,

Thanks for following up and letting me know that you got it working! That’s really great to hear! Please don’t hesitate to reach out if you have any further questions going forward. :slight_smile:

Best regards,

Kenny