0

In Jenkins execute Windows batch command:

rmdir "\\other_pc\dir"
deleteServerDir.bat

deleteServerDir.bat:

rmdir "\\other_pc\dir"

These two methods failed both, the console output is:

xxx\Jenkins|workspace\test>rmdir "\\other_pc\dir"
Access is Denied

However, both work when I type rmdir "\\other_pc\dir" in cmd window or directly run file deleteServerDir.bat.

It seems that Jenkins do not know the username and password which I used and stored in Windows to log into \\other_pc\dir.

Mofi
  • 46,139
  • 17
  • 80
  • 143
gpu
  • 129
  • 10
  • 1
    Jenkins runs on Windows as service using built-in system account. The system account of a machine has usually no permissions to access any shared folder on another machine. The credentials entered by you to access the shared folder on a different PC is stored by Windows encrypted in Windows registry for your user account and not for any account used on this machine. Credentials to access something on other machines are saved for security always per account and never for all accounts of a machine. – Mofi Jul 09 '20 at 11:24
  • 1
    It would be a security nightmare if one user enters on a machine credentials to get access to data stored on a different machine and all other users using also the machine as the user who entered the credentials have then also access to the data on the different machine without the need to enter user name and password to access the data on the other machine. – Mofi Jul 09 '20 at 11:25
  • 1
    You can configure on `other_pc` that the directory `dir` can be accessed by `Everyone` for read/write/delete whereby it would be better to delete all files and subdirectories in `\\other_pc\dir` and not the directory `\\other_pc\dir` itself, see [How to delete files/subfolders in a specific directory at the command prompt in Windows?](https://stackoverflow.com/a/50656521/3074564) Well, I suppose your description is not 100% correct because of a subdirectory of `\\ComputerName\ShareName` should be deleted most likely and not the directory itself which is shared for access by other machines. – Mofi Jul 09 '20 at 11:26
  • 1
    But that would be no good idea as this means really everyone can access `\\ComputerName\ShareName` to read/write/delete files and folders on that shared folder. It would be possible to use for example `%SystemRoot%\System32\net.exe use Z: \\ComputerName\ShareName "password" "/user:username" /persistent:no` to mount the shared folder with the specified credentials as drive `Z:`, use that network drive, and finally disconnect with `%SystemRoot%\System32\net.exe use Z: /delete /yes`. But that is also not good as everyone with access to Jenkins can see password and user name. – Mofi Jul 09 '20 at 11:31
  • But it is a common task that a Jenkins job needs to access a storage media on a different machine/device using specific credentials like user name and password or a public/private key. For that reason there are plugins available for Jenkins which can be used in a Jenkins job configuration to connect to a shared folder on a different machine using the credentials entered on configuring the Jenkins job with using the plugin and with saving the credentials encrypted on the machine running Jenkins so that nobody can find out the credential data used to access the shared folder on job execution. – Mofi Jul 09 '20 at 11:38
  • thank you so much! do you know what's the name of the plugin? – gpu Jul 10 '20 at 02:07
  • 1
    No, I don't know the names of suitable Jenkins plugins as I am not a Jenkins expert. You have to search for a suitable plugin by yourself, but I am 100% sure that there is a plugin as I know from others without remembering the name of the plugin. – Mofi Jul 10 '20 at 07:08
  • by now I resolve the problem by add this in cmd in Jenkins before I access the other PC,```%SystemRoot%\System32\net.exe use Z: \\ComputerName\ShareName "password" "/user:username" /persistent:yes```, I donot call```%SystemRoot%\System32\net.exe use Z: /delete /yes```, because if I called this, it will only work for the 1st time after everytime the PC started, and I still donot know why... – gpu Jul 10 '20 at 10:17

0 Answers0