Xcopy is not working in octopus deploy?

Hi Team,

I’m trying to copy files using xcopy in octopus deploy. But seems xcopy is not working. Here is the command I’m using in PostDeploy.ps1
xcopy Content C:\websitecode /e /y /exclude:test.txt

Reason for using xcopy is I can exclude multiple files.

Can someone please help me how to use xcopy in octopus deploy…

Thank you.

Hi Kumar,

Thanks for getting in touch. I know you are asking specifically about getting xcopy to work in your deployment, but I would really like to understand your situation better. Octopus has many built-in features that help with deploying websites which you might be able to leverage with some small changes to your hosting.

So, some questions to help me understand your situation better:

  1. How important is it that your website files be in the fixed path C:\websitecode?
  2. How many files do you want to exclude from the copy?
  3. Which version of IIS are you hosting your website in?

Generally I recommend letting Octopus handle the file system and IIS for your deployment and only customising if necessary. You will get a lot of benefits for free doing this, and it also helps you avoid common pitfalls of using a fixed folder or custom process.

In your situation you want to remove files after the deployment is complete, and you could use one of our Step Templates for that. In this case the steps in your process would look something like:

  1. Deploy your IIS Website (without needing XCOPY or any other customisations)
  2. File System - Clean Directory to clean up the files you don’t want anymore

In this case you would “chain” those two steps together using the output variable Octopus.Action[YourWebSiteStepName].Output.Package.InstallationDirectoryPath.

Hope that helps!
Mike

Hi Mike,

Thank you so much for the reply. In my case C:\websitecode is just dummy folder. and I have some *.config files and *.xsd and few other folders to be exclude while copying. This is the main reason for using using xcopy. IIS version is 7.0
Currently I’m just trying to copy files using xcopy.

Please help me how can I execute xcopy command from octopus deploy.

Thank you mike.

Hi Kumar,

Thanks for getting back to me. I’ll see if I can help you get xcopy working, but I will admit I’m concerned that you will end up negating benefits that the default IIS deployment process in Octopus offers you.

You can run anything you want inside PostDeploy.ps1 - At my best guess (without the deployment log) I think you are running into an issue with relative path resolution.

Here’s a couple of steps you could use to diagnose what is going wrong:

  1. Put a dir statement just before the xcopy statement - this will show you the directory listing in the Current Working Directory for the script
  2. Consider using the Custom Installation Directory feature
  3. Try debugging the script by running Calamari.exe interactively as described here

Failing this you could send me the deployment log and I’ll see if I can help you further.

Hope that helps!
Mike

Hi Kumar,

Another suggestion I neglected to add is:

  1. Consider using the Copy-Item PowerShell cmdlet which lets you set filters and excludes.

(Thanks to Dalmiro for the suggestion)

Hope that helps!
Mike

Thank you so much for the help Michael Noonan.:slight_smile: