Executing DOS Commands

  1. Create a project as normal
  2. Under Pre or Post Steps select "Execute Windows Batch Command"
  3. Enter any DOS command
    1. you must enter the full path to the command, unless it is an internal command like copy, delete etc.
    2. the confusion around this menu option is it sounds like you can execute the .bat file and internal command like copy, delete etc.  The reality is, any command that can be executed from within a batch file can be executed within the panel you are presented with
    3. Any commands where the PATH or filename comprise of spaces, should be enclosed in "" (double quotes), DO NOT include within the quotes the arguments to the command. e.g. "C:\Program Files\Docker Toolbox\docker.exe" cp --help

Gotcha

Even though you do the above, the command may fail with an error message telling you the client must be executed in a privileged state, this is really referring to Jenkins as the client.  Go to Windows Services and locate Jenkins, you will see that it is executing as LocalSystem

This isn't good enough.  Do the following

  1. Open up the properties dialog
  2. Select Log On
  3. Select Browse
  4. Enter a name that has administrator privileges (it doesn't have to be Administrator as shown below - on my Windows 10 Home laptop I've put my login name as I have admin rights)
  5. Select Check Names, if the name is valid the user named will be prefixed with the machine name
  6. Select OK, and Apply through all other dialogs to get back to the Windows Services Window