The system cannot find the specified drive in Jenkins
Asked Answered
P

9

11

I want to copy some files from a network shared drive (mounted at my local machine as drive Z). I have written a Batch file to copy the contents of Z drive into my local drive. This batch file runs successfully on cmd, but i am having issue when i trigger it through Jenkins. The Jenkins gives the following error:

"The system cannot find the specified drive"

Any help regarding this, will be greatly appreciated.

Thanks, Nouman.

Pooler answered 29/11, 2012 at 7:2 Comment(0)
J
10

If you don't want to use Jenkins-plugins or schedule-Tasks here is a "groovy" way:

By Hand:

You can use the Groovy Script-Console provided by Jenkins>Manage Jenkins>Script Console and execute the command to map the network-drive within the Jenkins-service. (Must be repeated, once the Jenkins-service is stopped)

Automation:

Write your Groovy commands to a file named "init.groovy" and place it in your JENKINS_HOME-directory. So the network-drive gets mapped on Jenkins-startup.

Groovy Commands - Windows:

Check available network drives using the Script-Console:

println "net use".execute().getText()

Your init.groovy would look like this:

def mapdrive = "net use z: \\\\YOUR_REMOTE_MACHINE\\SHARED_FOLDERNAME"
mapdrive.execute()
Janssen answered 5/6, 2013 at 9:32 Comment(2)
Nice, I wasn't aware of these. Sadly, in my case I need to dynamically fetch a free drive letter, and then assign it to a newly-created UNC path (ClearCase view) that's created at run-time. Problem is, any build-step that needs the mapping has to repeatedly re-map the drive manually in every "Execute Windows Batch Command" build-step.Leukemia
How would you map two different drives?Greenwich
H
2

Yes Jenkins uses different login credentials. To map a drives through Jenkins use below command in Jenkins command prompt:

Subst U: \drive\folder

then after that your queries.

Hord answered 28/6, 2016 at 5:41 Comment(1)
I would add that you need to make sure that you have C:\Windows\System32 added to the PATH environment variable, which you need to add to: Jenkins > Manage Jenkins > Configure System.Cwm
C
1

You might run into permission issues. Jenkins might be executed with different user credentials; so it does not know the configured drive for the windows share. Instead of using shell scripts I suggest to use a plugin. There is a set of Publish-over plugins that allow deployments to remote systems via a couple of protocols (ssh, cfis etc). Have a look at the CFIS plugin that allows to send artifacts to a windows share. Once the plugin is configured (ie the host is specified in the Manage Jenkins section) you can add to the post build steps Send files to a windows share where you can specify which file(s) shall be sent to which location.

Camembert answered 29/11, 2012 at 12:32 Comment(2)
If you are running Jenkins as a Windows Service, then it is running as user "NT AUTHORITY\SYSTEM", which will most likely have different settings, permissions, etc then you or a regular user. To see how your batch file will execute from a cmd shell of your own, refer to the question How to run commands as NT AUTHORITY... on serverfault.Pietro
Jenkins allows the service to run with a specified user/password in the node configuration.Leukemia
B
1

Had this issue where my jenkins job was unable to read files present on the network drive. I resolved it by adding "net use" command in your pre-build step. i.e.

Open your job. Go to Pre Steps From the drop down, select Execute Windows Batch Command Enter the following command: net use E: \[server name][Folder name] "[password]" /user:"[userid]" Click Save Execute the job

I was able to read files from my network drive by following the steps mentioned above.

It seemed to be a one time activity as after the initial run, I had removed the batch command from my job and it seemed to remember the mapped drive command.

Bots answered 18/8, 2020 at 6:45 Comment(0)
A
0

Try adding debugging commands to that bat file, or as separate build step, such as net use, set (pay attention to vars like like HOMEPATH and USERNAME) and plain dir Z:\.

As said in another answer, most likely reason is that Jenkins runs as SYSTEM user, which has different permissions. One way around that is, go to services (for example open Task Manager, go to Services tab in it, click the Services button at the lower right corner of that tab), find Jenkins service, open it's properties, go to "Log on" tab and set your normal user account as one that runs Jenkins.

Associationism answered 3/12, 2012 at 21:0 Comment(0)
C
0

Basically you can access your network shared drive (Z) using by servername or IP from jenkins command. Write \\192.168.x.xxx\Your_Folder instead of z:\Your_Folder.

For example:

mkdir \\192.168.x.xxx\Your_Folder
Capello answered 22/11, 2018 at 11:39 Comment(0)
T
0

I was trying to copy files from one remote computer to other, the easy solution which worked for me is COPY iphone.exe \192.xx.xx.xx\dev(dev is the folder name on c drive in that ip address)

Timecard answered 22/1, 2019 at 15:45 Comment(0)
C
0

A similar issue showed up for us on Jenkins slaves set up on Windows Server 2008 following this documentation. The Jenkins agent failed to access the mounted network drives even after configuring the agent service with the correct user credentials.

Troubleshooting:

  1. Jenkins could access the mounted network drives by their drive letters when connected via the JNLP agent (Launch agent via Java Web Start).
  2. It stops recognizing the drive letters soon after we install the agent as a Windows service. Configuring the correct user credentials and restarting the agent does not help.
  3. We could still access the drives via the command line while logged in to the machine with the above user.
  4. Stop the agent service from services.msc and then uninstall it by running the command jenkins-slave.exe uninstall. The slave is disconnected at this point.
  5. Reconnect the slave by launching the JNLP agent via Java Web Start. The agent can now access the network drives again.

Synopsis:

Do not install the slave agent as a Windows service to keep accessing your mounted network drives using drive letters. But this is highly unreliable as the agent might fail to restart after a machine reboot. Alternatively, see if Jenkins can access them via \\<ip_address\of\network\drive>.

Chor answered 19/4, 2019 at 11:8 Comment(0)
S
0

In order to access your remote drive

just use the command in cmd prompt


  • pushd "\sharedDrive\Folder1\DestinationFolder"

  • mkdir FolderName

  • popd


pushd >> It navigates to the shared drive by creating a virtual drive.. popd >> Gets you back to the local directory

Sava answered 20/3, 2020 at 12:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.