Invoking batch file that contains XCopy statements does nothing within octopus

This is my simple powershell script, its purpose is to chdir and then run a batch file that just xcopys files to directory.

$batchpath = "C:\MyPath\Folder"
$cmd = "1.CopyStuff.bat"

write-host "Calling $cmd"
set-location $batchpath 

# run under .\ to inherit the env
& .\$cmd

The batch file is very simple - it just copies some files to a new location with relative paths

xcopy ".\APath\Path1" ".\bin\Path1\" /E /H /R /Y
xcopy ".\APath\Path2" ".\bin\Path2\" /E /H /R /Y

When I run this ‘step’ inside Octopus nothing happens; all i get is the xcopy commands echod out… IThe script finds the file correctly and invokes it but something is amiss.

Running PowerShell script: C:\Documents and Settings\Default User\Local Settings\Application Data\Tentacle\Temp\bdbf8270-d6b7-4395-aad6-84a146ddddac.ps1
Info    17:36:54
Calling 1.PrepForDeployment.bat
C:\MyPath\Folder>xcopy ".\APath\Path1" ".\bin\Path1" /E /H /R /Y 
C:\MyPath\Folder>xcopy ".\APath\Path2"  ".\bin\Path1" /E /H /R /Y 

Info    17:36:54
==============================================
PowerShell exit code: 0
==============================================

If i run it via the tentacle command line (octo.ps1 is the guid renamed before octopus deletes it) it works fine, the files are all copied correctly.

*note I am logged on as admin when i invoke this command*
C:\Documents and Settings\Default User\Local Settings\Application Data\Tentacle\Temp>Tentacle.exe run-script -f octo.ps1

I see output like this

C:\Documents and Settings\Default User\Local Settings\Application Data\Tentacl
Octopus Deploy: Tentacle version 2.6.5.1010

Script: C:\Documents and Settings\Default User\Local Settings\Application Data
Working dir: C:\Documents and Settings\Default User\Local Settings\Application
Variables:
Running script...
Calling 1.PrepForDeployment.bat
C:\MyPath\Folder>xcopy ".\APath\Path1" ".\bin\Path1" /E /H /R /Y 
C:\MyPath\Folder>xcopy ".\APath\Path1" ".
.\bin\Path1\File1.txt
.\bin\Path1\File2.txt

Can anybody shed any light as to why the tentacle command line works but the octopus build step does not?

Thanks

Steve

Hi Steve,

Thanks for getting in touch. This is the output i get when i run the same code you copied.

Calling 1.CopyStuff.bat
C:\test>xcopy ".\APath\Path2" ".\bin\Path2" /E /H /R /Y 
.\APath\Path2\TestConfig.nuspec
.\APath\Path2\Web.Config
.\APath\Path2\web.release.config
3 File(s) copied
C:\test>xcopy ".\APath\Path1" ".\bin\Path1" /E /H /R /Y 
.\APath\Path1\TestConfig.nuspec
.\APath\Path1\Web.Config
.\APath\Path1\web.release.config
3 File(s) copied
Info    15:42:39
==============================================
PowerShell exit code: 0
==============================================

Seems to work fine on my end.

May I ask why are you not using straight powershell for this, instead of doing an extra hop using a batch with xcopy(which is most likely generating the issue)?

This script should do the same for example:

$source = "c:\test"

#Path1
Copy-Item "$source\APath\Path1\*" "$source\bin\Path1" -Recurse -Force -Verbose #take away -verbose to avoid verbosity

#Path2
Copy-Item "$source\APath\Path2\*" "$source\bin\Path2" -Recurse -Force -Verbose #take away -verbose to avoid verbosity

Let me know if it works for you.

Thanks,

Dalmiro

Thanks for the reply, seems I am not alone with this issue.

http://help.octopusdeploy.com/discussions/problems/6741-xcopy-seems-to-be-ignored

I tried every combination and in the end replaced the xcopy with robocopy and things worked as expected.

Did you run the script in octopus or just in Tentacle. Mine worked as expected from tentacle.exe - however the instant the step runs inside octopus the xcopy just did nothing.

Reason i am using batch files is because they already exist and work and we still need to maintain the option of being able to deploy simply from outside octopus. For now the plan is to have octopus invoke the required scripts on various machines. (incrementally we will be replacing with powershell)

Hi Steve,

I ran it in Octopus as part of a deployment (see attached screenshot). It must be an environmental thing then. The Robocopy workaround sounds fair enough though :slight_smile: (until you can go all-Powershell).

Cheers!

forgot the screenshot :slight_smile:

I also have this problem. Doesn’t matter if I attempt to run xcopy from PowerShell directly or from a cmd script.

My script:

get-command xcopy | fl
& xcopy /?
cmd /c where xcopy
cmd /c xcopy /?

The result:

Executing script on 'VRC-DEV-WEB'
Name            : xcopy.exe
CommandType     : Application
Definition      : C:\Windows\system32\xcopy.exe
Extension       : .exe
Path            : C:\Windows\system32\xcopy.exe
FileVersionInfo : File:             C:\Windows\system32\xcopy.exe
                  InternalName:     xcopy
                  OriginalFilename: XCOPY.EXE
                  FileVersion:      6.1.7600.16385 (win7_rtm.090713-1255)
                  FileDescription:  Extended Copy Utility
                  Product:          Microsoftr Windowsr Operating System
                  ProductVersion:   6.1.7600.16385
                  Debug:            False
                  Patched:          False
                  PreRelease:       False
                  PrivateBuild:     False
                  SpecialBuild:     False
                  Language:         English (United States)

C:\Windows\System32\xcopy.exe

Notice that neither powershell nor cmd.exe have trouble finding xcopy.exe, but neither of the invocations of xcopy /? produce help text, either.

This is consistent behavior for me across all of my environments under Octopus, and it has resulted in many hours of trying to figure out why file copying doesn’t always work. Turns out we have to use robocopy and plain ol’ copy under Octopus because xcopy is a complete no-op.