Execute windows batch command from Jenkins fails but runs fine in cmd.exe Execute windows batch command from Jenkins fails but runs fine in cmd.exe jenkins jenkins

Execute windows batch command from Jenkins fails but runs fine in cmd.exe


I too had a similar issue once. Try granting the Jenkins service "Logon as This account" right under services.msc and make sure the account you type there is the same as the one you use for running cmd.exe.

enter image description here


These commands based on Java JAR files worked for me:
cmd
net use x: \\
xcopy "dist\" x:\ /Y

And that's it! I spent lot of time figure out this issue and nothing worked until I wrote CMD and NET USE!
Neither I didn't need to change permission on jenkins service nor use runas command.

But I must mention that everyone had read and write access to the network drive.


I had the same issue with my Windows Task running a batch file (I know it is not exactly same) where I tried to copy file to network location i.e. shared drive. I used the UNC path and mapped drive as well but the error was same. For me it was error number 4 - MS DOS error code.The solution was to use net use command! Hope that it helps.