XCOPY seems to be ignored

We’ve got a bit of code like this in our PreDeploy script that copies the existing config out of our site prior to deployment.
@@@
$webSite = Get-Item $webSitePath
if($webSite)
{
$physicalPath = $webSite.physicalPath + “*.config”
$backupPath = "c:\WorkArea\Backup$IisSiteName"
xcopy “$physicalPath” “$backupPath” /S /Y | Write-Host
}
else
{
Write-Host “Website $IisSiteName does not already exist!!”
}
@@@

Regardless of what we do this seems to be ignored… nothing is being written to the output.

When we run it locally it works and when we run it on the tentacle with Tentacle.exe it works fine.

What are we doing wrong?

Cheers,
Graeme.

Hi Graeme,

You might need to add an ampersand to ensure xcopy is invoked:

& xcopy ....

If that doesn’t work can you attach the output from your deployment log?

Paul

There doesn’t seem to be anything relevant in the output ( I can email it to you via email but I’m not sure it offers much info)

Here is the relevant section of our PreDeploy.ps1 and the correseponding section of the output, you can see where we’re doing a bit of diagnostic write-host that seems to imply it’s just being ignored? any help would be very grately apprciated as always!

PreDeploy snippet:
@@@
Import-Module WebAdministration
$webSitePath = (“IIS:\Sites\” + $IisSiteName)
Write-Host “webSitePath: $webSitePath”
$webSite = Get-Item $webSitePath
if($webSite)
{
Write-Host “Website found start copying files…”
$physicalPath = $webSite.physicalPath + “*.config”
$backupPath = "c:\WorkArea\Backup$IisSiteName\"
Write-Host “xcopy ‘$physicalPath’ ‘$backupPath’ /S /Y”
& xcopy “$physicalPath” “$backupPath” /S /Y | Write-Host
}
else
{
Write-Host “Website $IisSiteName does not already exist!!”
}
cd IIS:
Write-Host “DEBUG: webRoot = $webRoot”
@@@

Output snippet:
@@@
2013-04-16 07:27:37 INFO [PreDeploy Script] webSitePath: IIS:\Sites\Portal
2013-04-16 07:27:37 INFO [PreDeploy Script] Website found start copying files…
2013-04-16 07:27:37 INFO [PreDeploy Script] xcopy ‘C:\Octopus\Applications\Test_B\WebPortal\4.4.4853.43396\*.config’ ‘c:\WorkArea\Backup\Portal’ /S /Y
2013-04-16 07:27:37 INFO [PreDeploy Script] DEBUG: webRoot = C:\Octopus\Applications\Test_B\WebPortal\4.4.4854.22139
@@@

All we’re trying to do is copy OUT all .config files prior to the deployment so that we can copy them back and overwrite the new ones with the existing config after the deployment.

So that we’re effectively not updating the configuration.

I’ve tried changing the command from
@@@
& xcopy “$physicalPath” “$backupPath” /S /Y | Write-Host
@@@
to
@@@
& xcopy $physicalPath $backupPath /S /Y | Write-Host
@@@
and it still doesn’t work.

Cheers,
Graeme.

Hi Graeme,

Is your Tentacle windows service configured to run under a custom user account, or does it run as Local System (the default)?

Could you also try adding:

& dir | write-host

To your script to see if that appears in the output?

Paul

Hi Paul,
The tentacle on this box is running LocalSystem, what’s strange is that I’d expect it to at least output…
@@@
File not found - *.config
0 File(s) copied
@@@
If it couldn’t find anything.
I’ll try your suggestion and I’m just trying ROBOCOPY see if that will work.

Cheers,
Graeme.

ROBOCOPY seems to work, except that it change the return code to 1 when it has successfully copied files!

Hi Graeme,

Yes, Robocopy is a bit funny about this. You can add “exit 0” at the end of your script after Robocopy runs to reset the exit code back to zero.

Paul

We had the same problem.
My solution was to use this: Start-Process -FilePath xcopy.exe -ArgumentList “…” -Wait
PS: If I added -NoNewWindow (to get the output back) it would not run. Just like xcopy.

We’ve resorted to robocopy, but it’s good to know it wasn’t just us.

Cheers,Graeme.

n.b. our robocopy looks something like this for future reference:
@@@
& robocopy $backupWebRoot $webRoot *.config /S /COPYALL /IS /IT /R:10 | Write-Host
@@@