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

Access denied when copy files from a network computer in Windows batch script

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Not A Defect
    • Component/s: core
    • Labels:
      None
    • Similar Issues:
      Show 5 results

      Description

      I have a problem (Access is denied) when I try to copy files across network in a Windows batch script.

      Hudson will call a script, say, a.bat and inside a.bat I have the followings

      ...
      setlocal ENABLEDELAYEDEXPANSION
      ...
      
      if DEFINED abc (
         set xyz=\\computer\path
         set filename=mm*.dll
      
         copy /Y !xyz!\!filename!   
      )
      ...
      endlocal
      

      The 'copy' command will fail and I Google for the problem but there's no particular one. There's one paper saying UNC should be used (http://stackoverflow.com/questions/1284561/hudson-continuous-integration-server-how-to-see-windows-mapped-directories-that). So I did the following experiments:

      1) set xyz="//computer/path"
         ...
         copy /Y "!xyz!"\!filename!
      2) ...
         copy /Y "//computer/path"\mm*.dll
      

      The 1) doesn't work and produces the same problem - "Access is denied." but the 2) is working. However, copy /Y "//computer/path"!file_name! won't work either.

        Attachments

          Activity

          Hide
          bakerzhang bakerzhang added a comment - - edited

          Also I tried the followings in the script (a.bat) and failed:

          if EXIST R: net use R: /delete >nul
          net use R: \\computer\path
          set xyz=!xyz:\\computer\path=R:!
          copy R:\!filename!
          

          It failed at "net use R: \\computer\path" and shows "System error 59 has occurred." But I has not problem to run above from Command console.

          Show
          bakerzhang bakerzhang added a comment - - edited Also I tried the followings in the script (a.bat) and failed: if EXIST R: net use R: /delete >nul net use R: \\computer\path set xyz=!xyz:\\computer\path=R:! copy R:\!filename! It failed at "net use R: \\computer\path" and shows "System error 59 has occurred." But I has not problem to run above from Command console.
          Hide
          bakerzhang bakerzhang added a comment - - edited

          I tested the above method at the "Execute Windows batch command" they are still failing

          set xyz=\\computer\path
          set filename=mm*.dll
          copy /Y %xyz%\%filename%
          
          if EXIST R: net use R: /delete
          net use R: %xyz%
          set abc=\\computer\path
          set abc=%abc:\\computer\path=R:%
          copy /Y %abc%\%filename%
          

          But everything works fine in the Windows Cmd window, even in the project workspace.

          Show
          bakerzhang bakerzhang added a comment - - edited I tested the above method at the "Execute Windows batch command" they are still failing set xyz=\\computer\path set filename=mm*.dll copy /Y %xyz%\%filename% if EXIST R: net use R: /delete net use R: %xyz% set abc=\\computer\path set abc=%abc:\\computer\path=R:% copy /Y %abc%\%filename% But everything works fine in the Windows Cmd window, even in the project workspace.
          Hide
          xjom71 Mattias Vannergård added a comment -

          Same thing here.

          Neither net use or copy works when running as a "Execute Windows batch command" (but it works on a Command console), and I can't find a work-around either.

          Have someone found a work-around?

          regards
          /Mattias

          Show
          xjom71 Mattias Vannergård added a comment - Same thing here. Neither net use or copy works when running as a "Execute Windows batch command" (but it works on a Command console), and I can't find a work-around either. Have someone found a work-around? regards /Mattias
          Hide
          nvc Nick Vancauwenberghe added a comment - - edited

          I'm also hitting this issue. I can't access remote locations from Jenkins, while it works OK in Windows cmd. The machine has the correct permissions.

          I played around with other user accounts for the Jenkins service. My user account but the service failed to start (Windows error 1069: the service did not start due to a logon failure). The network service account did run but than Jenkins throws errors it can't access the .NET framework.

          No success, I'm also looking for a workaround or a solution.

          Some info:
          > The Jenkins machine OS is Windows 7 32-bit Prof. Jenkins is running as a service using a local system account.
          > I use UNC notation:
          target

          Regards,
          Nick

          Show
          nvc Nick Vancauwenberghe added a comment - - edited I'm also hitting this issue. I can't access remote locations from Jenkins, while it works OK in Windows cmd. The machine has the correct permissions. I played around with other user accounts for the Jenkins service. My user account but the service failed to start (Windows error 1069: the service did not start due to a logon failure). The network service account did run but than Jenkins throws errors it can't access the .NET framework. No success, I'm also looking for a workaround or a solution. Some info: > The Jenkins machine OS is Windows 7 32-bit Prof. Jenkins is running as a service using a local system account. > I use UNC notation: target Regards, Nick
          Hide
          nvc Nick Vancauwenberghe added a comment - - edited

          I almost sure this is the solution - it worked for me. See http://serverfault.com/questions/135867/howt-to-grant-network-access-to-localsystem-account
          You have to grant access persmission to the computer in a domain instead of to the user of that machine.

          A 2nd solution is to run the service using a domain user account, notation: "DOMAIN\user" and not ".\user".

          Show
          nvc Nick Vancauwenberghe added a comment - - edited I almost sure this is the solution - it worked for me. See http://serverfault.com/questions/135867/howt-to-grant-network-access-to-localsystem-account You have to grant access persmission to the computer in a domain instead of to the user of that machine. A 2nd solution is to run the service using a domain user account, notation: "DOMAIN\user" and not ".\user".
          Hide
          xjom71 Mattias Vannergård added a comment -

          Yep! 2nd solution worked for me.

          Thanks!
          /Mattias

          Show
          xjom71 Mattias Vannergård added a comment - Yep! 2nd solution worked for me. Thanks! /Mattias
          Hide
          sherry Sherry W added a comment -

          The 2nd solution works for me too.
          Thank you guys! You saved my day.

          Show
          sherry Sherry W added a comment - The 2nd solution works for me too. Thank you guys! You saved my day.

            People

            • Assignee:
              Unassigned
              Reporter:
              bakerzhang bakerzhang
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: