5

I am not able to get this to work

call "%MSDeployPath%msdeploy" -verb:sync -source:runCommand='backup.bat param1' -dest:auto,computername=10.xx.xx.xx,username=xxx,password=yyy

It gives me:

Warning: 'backup.bat' is not recognized as an internal or external command, operable program or batch file.

Warning: The process 'C:\Windows\system32\cmd.exe' (command line '') exited with code '0x1'. Total changes: 1 (0 added, 0 deleted, 1 updated, 0 parameters changed, 0 bytes copied)

If I remove the param1 and hardcode it inside the .bat, it works, so there's no problem with the bat file, in case you wonder.

I tried to specify the full path to .bat and it still doesn't work:

call "%MSDeployPath%msdeploy" -verb:sync -source:runCommand='c:\backup.bat param1' -dest:auto,computername=10.xx.xx.xx,username=xxx,password=yyy

In this case, it looks like it interprets the path as a remote path, it expects backup.bat to be on the server. This was confirmed to me after I moved backup.bat on the server, it worked

WHY does it have to be so HARD???

Andrei N.
  • 2,957
  • 2
  • 31
  • 54

1 Answers1

7

Edit You are right, the documentation states that cmd/bat files will be streamed to the destination.

It seems to me that it's simply a limitation of the feature that it can't accept arguments. It shouldn't be too difficult to create a modified version of the batch file at deploy-time with the settings hardcoded.

Something like:

REM Start of prepended script
SET SCRIPT_USERNAME=ThatGuy
REM End of prepended script

IF ("%SCRIPT_USERNAME%" == "") SET SCRIPT_USERNAME=%1

Update Having browsed the reflected source (ahem) of msdeploy, I can confirm that it's simply the way it's current designed. It determines whether to upload the file based on whether the entire path represents a file. Since adding arguments will prevent it resolving the path to a file, it doesn't upload anything.

Richard Szalay
  • 78,647
  • 19
  • 169
  • 223
  • not true. runCommand is able to stream and execute the .bat file, the .bat file does not need to be on the destination server. From the same link you provided, it says: "If you specify a batch file or a command file, the file will be streamed to the destination computer and run as a local command on the destination computer". the problem is I am not able to pass parameters for the batch file – Andrei N. Oct 04 '12 at 13:31
  • Hi both, I know this was a year ago but have there been any developments in this area at all? I'm trying to do the same thing with a single script on the deployment server, and then call it with different arguments. – WheretheresaWill Oct 09 '13 at 10:19
  • @WheretheresaWill - I don't believe this behaviour was changed in 3.5, so I'd say it's still the same. Your only real choice would be to set environment variables in the environment. – Richard Szalay Oct 09 '13 at 11:08
  • @RichardSzalay thanks again for your helpful posts - everytime I have MSDeploy issues I stumble across one of your answers/blogs! Anyway, I think I'll rework it so that the scripts are site-specific and get synced and then run upon deployment... Not as clean, but should do the job. – WheretheresaWill Oct 09 '13 at 13:16