Execute windows batch command from Jenkins fails b

2019-02-03 08:39发布

I am trying to run this command in jenkins after a MSbuild

xcopy "C:\Program Files (x86)\Jenkins\workspace\trunk\Projects\results\results\obj\Debug\Package\PackageTmp" "Y:\Extraction_Zone\Jenkins\" /E 

Y: is a mapped network drive. This runs fine in cmd.exe but when trying to run it in Jenkins, I am getting the error Invalid drive specification.

Here is the output from jenkins:

Time Elapsed 00:00:04.03
[trunk] $ cmd /c call C:\Windows\TEMP\hudson3389873107474371072.bat

C:\Program Files (x86)\Jenkins\workspace\trunk>xcopy "C:\Program Files (x86)\Jenkins\workspace\trunk\Projects\results\results\obj\Debug\Package\PackageTmp" "Y:\Extraction_Zone\Jenkins\" /E 
Invalid drive specification
0 File(s) copied

C:\Program Files (x86)\Jenkins\workspace\trunk>exit 4 
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE

Any help would be appreciated.

7条回答
闹够了就滚
2楼-- · 2019-02-03 09:21

Easy fix for most things.

  1. Make a batch command with what your trying to run, filename.bat with the command prompt text inside.
  2. Make a normal windows shortcut for the batch command, edit the shortcuts advanced properties and check the "Run as admin" (tricky tricky).
  3. Now run the filename.lnk shortcut from jenkins command line call, this will get you around all the jazz.

:)

查看更多
祖国的老花朵
3楼-- · 2019-02-03 09:28

Faced similar issue and found two ways to solve.

Type 1: Tell Jenkins about mapped drive. 1.Goto -> Manage Jenkins -> Script Console (Groovy Script). 2.Run below command

 def mapdrive = "net use Y: \\\\copy_nework_address"
 mapdrive.execute();
 println "net use".execute().getText()

Type:2 1.Goto -> cmd -> run "net use" to know network address

xcopy "C:\Program Files (x86)\Jenkins\workspace\trunk\Projects\results\results\obj\Debug\Package\PackageTmp" "Copy_Network_Address\Extraction_Zone\Jenkins\" /E

Conclusion:- I prefer 2nd types as after every restart i should run Groovy Script.

查看更多
Explosion°爆炸
4楼-- · 2019-02-03 09:29

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.

查看更多
我命由我不由天
5楼-- · 2019-02-03 09:30

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.

查看更多
啃猪蹄的小仙女
6楼-- · 2019-02-03 09:30

I've solved my issue with the CIFS plugin.

查看更多
Viruses.
7楼-- · 2019-02-03 09:40

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

查看更多
登录 后发表回答