access denied using mkdir and rmdir in jenkins

喜欢而已 提交于 2020-02-07 02:36:14

问题


Jenkins is generating a build of a C++ project made in Visual Studio.

During the process, some .bats are called and in one of them, there is a structure like this:

SET TEMPDIR=Temp
rmdir %TEMPDIR% /S /Q
echo Don't continue if there was an error above (except the not found error which is ok) and go hand delete the dir!
:pause
mkdir %TEMPDIR%

I'm not very familiar to batch scripting, but when both rmdir and mkdir are called, Jenkins gives me access denied.

I looked in the build configurations to search for any type of read/write permissions but it seems there isn't any.

How can I fix this? Later the other scripts try to access Temp but they fail and it breaks my build.


回答1:


Some of the reasons rmdir can fail:

  • No permissions
  • The directory contains files.
  • It's the current working directory of one or more processes.
  • A process has a lock on it.

Some the reasons mkdir can fail:

  • No permissions
  • The directory already exists.

The OP's script is attempting to create a directory named "Temp" in whatever the %CD% is for the process running that script. If there are other processes that also run that script, or any that avail themselves of the same %CD%\Temp path for any reason, then there can be failures for both creating or deleting that path.


It is common in build systems, for there to be multiple parallel processes and threads running a variety of programs/scripts in a variety of working directories. From the perspective of any instance of a cmd file, any path that is %CD% relative, is effectively random. All descent CI build systems provide environment variables that such programs/scripts can use to orient themselves correctly, relative to a known build root of some form, often called something like BuildRoot.

But the real issue here is how the OP's scripts are handling temp directory management. They simply aren't robust enough to be sharing a common temp directory.


I would add that a good CI build system, provides some form of per-process/thread temp directory, that programs/scripts can use without having to do any directory management.



来源:https://stackoverflow.com/questions/59912113/access-denied-using-mkdir-and-rmdir-in-jenkins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!