18

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.

Chris
  • 1,163
  • 3
  • 13
  • 22
  • 3
    isn't jenkins running as a service ? If that's true, you should resolve your issuer by specifing the network path in place of the mapped drive – Steve B Jun 08 '12 at 16:05
  • 2
    Y: is probably mapped to a specific user. Jenkins probably runs under its own 'service account' with no access to that drive letter Y:? You can try using UNC pathing instead of Y:, i.e. "\\ServerName\Folder\Extraction_zone\Jenkins\" – JMC Jun 08 '12 at 16:06
  • Thanks for the replies. I tried this, but am getting access is denied: `Time Elapsed 00:00:03.70 [trunk] $ cmd /c call C:\Windows\TEMP\hudson7535872922876977589.bat C:\Program Files (x86)\Jenkins\workspace\trunk>xcopy "C:\Program Files (x86)\Jenkins\workspace\trunk\Projects\results\results\obj\Debug\Package\PackageTmp" "\\COMP-NAME\Webs\Extraction_Zone" /E Access denied Unable to create directory - \\COMP-NAME\Webs\Extraction_Zone 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` – Chris Jun 08 '12 at 16:19
  • I realized I forgot the \Jenkins part of the path, but still getting the Invalid drive specification error: `C:\Program Files (x86)\Jenkins\workspace\trunk>xcopy "C:\Program Files (x86)\Jenkins\workspace\trunk\Projects\results\results\obj\Debug\Package\PackageTmp" "\\COMP-NAME\Webs\Extraction_Zone\Jenkins\" /E Invalid drive specification` – Chris Jun 08 '12 at 16:32
  • Did you resolve this? I am encountering something similar (Jenkins behaviour differs from command-line) – Kohanz Feb 11 '13 at 14:31

7 Answers7

17

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

adarshr
  • 61,315
  • 23
  • 138
  • 167
  • This didnt seem to work. I tried logging in as Administrator, but I'm getting the same error. – Chris Jun 08 '12 at 16:12
  • 1
    I'm running from my work machine and I had this same issue. I did as @adarshr suggested and used This Account and Browse... then looked up my corprate AD account info and password. Worked like a charm! – TWhite Mar 13 '14 at 18:16
  • i had an issue with this: after changing the user the service would start and then stop. check the event viewer for more info. in my case my user didn't have access to C:\program files\jenkins – DLeh Mar 17 '15 at 17:59
  • If you came here via GIT options not working in your batch, but working in cmd.exe : https://issues.jenkins-ci.org/browse/JENKINS-34082 – Peter PitLock May 24 '17 at 07:38
4

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.

GuybrushThreepwood
  • 5,598
  • 9
  • 55
  • 113
Jiří
  • 41
  • 1
  • 1
    This made it work for me too, (I already had the jenkins server according to @adarshr 's reply). For improved readability the second line means `net use x: \\yournetworkshare\foldername` – Schaki May 13 '15 at 12:27
  • This fixed my Python scripts as well that were attempting to write to a network location. Changing/updating the Log On user didn't do the trick... – radix07 Aug 24 '18 at 15:09
1

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.

user3104116
  • 153
  • 1
  • 11
1

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.

:)

YakovL
  • 7,557
  • 12
  • 62
  • 102
0

The solution of adarshr (i.e., modifying the log on credentials of the service) has worked for me for a part of the problem: in my case, this allowed me to successfully check out a mercurial repository (using ssh protocol), which I could not do when using 'Local System account'.

However, I still have different behavior between running a command-line script or running the same script from a jenkins 'execute shell' script in the build section. In my case, I compile a Python extension. In Jenkins, I cannot import the extension (I don't see any error, but the execution simply stops, so I suspect it crashes).

If I uninstall the service and run the slave agent as a Java Web Start, I do get the same behavoir. It is a temporary fix for me, but it means that when I reboot the windows build machine, I have to manually re-start the Java Web Start application.

So -at least in my case- it is clear that this is a credential problem.

Credentials usage documentation: https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+CLI

HX_unbanned
  • 583
  • 1
  • 15
  • 51
mfiers
  • 389
  • 3
  • 7
0

I've solved my issue with the CIFS plugin.

swist
  • 1,111
  • 8
  • 18
0

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.