Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-50872

Mapped drives are not accessible to "Execute Windows Batch Command"

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • core

      This issue is specific to "Execute Windows batch command" build step in Jenkins Core.

      The slave machine has a given drive [Z:] mapped.

      On my windows 7 slaves, I can use the mapped drive in this without issue.
      On windows 10, I am told:
      The system cannot find the drive specified
      In an attempt to work around this, I have attempted to use "net use" to list the mapped drives available through this Jenkins job, and have also attempted to use "net use" to map the drive.

      To do this, I have set my Windows Batch Command to the following:

      net use
      net use z: [Drive mapping] /P:Yes
      

      Executing the job at this point gives me the following incredibly confusing console output:

      c:\workspace\Pull Jobs test\label\SSW106416>net use 
      New connections will be remembered.
      
      There are no entries in the list.
      
      
      c:\workspace\Pull Jobs test\label\SSW106416>net use z: \\[Drive mapping] /P:Yes 
      z: has a remembered connection to \\[Drive mapping]. Do you
      want to overwrite the remembered connection? (Y/N) [Y]: 
      No valid response was provided.
      

      I have also had the job execute "whoami" to confirm that I am using a properly authorized user to execute the batch commands.  Am I missing something here?  These all work locally on the slave, but however jenkins runs these batch commands seems to break it.

          [JENKINS-50872] Mapped drives are not accessible to "Execute Windows Batch Command"

          I was able to fix this with the groovy console using println "net use z: [drive mapping]".execute().getText()

          But this still seems like it must be an issue

          Benjamin Wagner added a comment - I was able to fix this with the groovy console using println "net use z: [drive mapping] ".execute().getText() But this still seems like it must be an issue

          Oleg Nenashev added a comment -

          In your case you run "net use" in the interactive mode, so it asks you for permissions to override the previous mapping. You need to somehow run this command in batch mode with proper approval flags.

          I doubt that mapping drives from Jenkins is a good idea. I would rather suggest using https://github.com/kohsuke/winsw/blob/master/doc/extensions/sharedDirectoryMapper.md which is available when you run Windows agents as services.

          Oleg Nenashev added a comment - In your case you run "net use" in the interactive mode, so it asks you for permissions to override the previous mapping. You need to somehow run this command in batch mode with proper approval flags. I doubt that mapping drives from Jenkins is a good idea. I would rather suggest using https://github.com/kohsuke/winsw/blob/master/doc/extensions/sharedDirectoryMapper.md which is available when you run Windows agents as services.

          Oleg Nenashev added a comment -

          Not a defect IMHO

          Oleg Nenashev added a comment - Not a defect IMHO

          The point that I'm driving at is that this was not an issue on Windows 7.  On Windows 7 if it is mapped on the computer, it is already mapped for jenkins.  Furthermore, I cannot install Jenkins as a windows service as it introduces another wall of limitations for my company's particular use.

          Mapping the drives from jenkins was never the original intent, it was simply the workaround for my issue.  The core issue is that Z: is mapped for the user on that very slave and Jenkins has no capability to find it.

          Benjamin Wagner added a comment - The point that I'm driving at is that this was not an issue on Windows 7.  On Windows 7 if it is mapped on the computer, it is already mapped for jenkins.  Furthermore, I cannot install Jenkins as a windows service as it introduces another wall of limitations for my company's particular use. Mapping the drives from jenkins was never the original intent, it was simply the workaround for my issue.  The core issue is that Z: is mapped for the user on that very slave and Jenkins has no capability to find it.

          Doru Florea added a comment - - edited

          I have the same issue on a Windows Server 2012 VM.

          I had a very old Jenkins v1.571 slave working just fine on the same machine.

          Now I'm upgrading to the latest Jenkins 2.107.3 and running the agent as a Windows service.
          The service is logged on as a specific account (not the local system account and not a Jenkins account) but it seems that the network profile of the specific user is not loaded by Jenkins so the mapped drives are not found.

          I found this to work as a workaround but maybe Jenkins should be able to manage this by default:
          https://support.asperasoft.com/hc/en-us/articles/216127818-How-to-map-network-shares-into-drives-to-a-Windows-service-permanently

          Also, It works if I connect the agent by running in a cmd the same command that launches the Windows service:
          java.exe -Xrs  -jar slave.jar -jnlpUrl <Jenkins_URL>/computer/<agent_name>/slave-agent.jnlp -secret <secret>

          Doru Florea added a comment - - edited I have the same issue on a Windows Server 2012 VM. I had a very old Jenkins v1.571 slave working just fine on the same machine. Now I'm upgrading to the latest Jenkins 2.107.3 and running the agent as a Windows service. The service is logged on as a specific account (not the local system account and not a Jenkins account) but it seems that the network profile of the specific user is not loaded by Jenkins so the mapped drives are not found. I found this to work as a workaround but maybe Jenkins should be able to manage this by default: https://support.asperasoft.com/hc/en-us/articles/216127818-How-to-map-network-shares-into-drives-to-a-Windows-service-permanently Also, It works if I connect the agent by running in a cmd the same command that launches the Windows service: java.exe -Xrs  -jar slave.jar -jnlpUrl <Jenkins_URL>/computer/<agent_name>/slave-agent.jnlp -secret <secret>

          Oleg Nenashev added a comment -

          doruflorea https://github.com/kohsuke/winsw/blob/master/doc/extensions/sharedDirectoryMapper.md is the way how Jenkins manages it now.

          The auto-mapping functionality could be also added to https://plugins.jenkins.io/external-workspace-manager , feel free to create a ticket for that.

          Oleg Nenashev added a comment - doruflorea https://github.com/kohsuke/winsw/blob/master/doc/extensions/sharedDirectoryMapper.md is the way how Jenkins manages it now. The auto-mapping functionality could be also added to https://plugins.jenkins.io/external-workspace-manager , feel free to create a ticket for that.

            Unassigned Unassigned
            shortcipher Benjamin Wagner
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: