简体   繁体   中英

The process cannot access the file because it is being used by another process. Jenkins Build

When we abort one of the Jenkins Job builds running on windows slave, and then try to retrigger, that new triggered build fails with below error:

The process cannot access the file because it is being used by another process.

while deleting the workspace.

Possibly when the build job was killed, some process that it spawned was not killed along with it, and that process was holding the file opened.

Often that process will finish running on its own and when it does finish, the lock on the file will be released.

If the process does not go away on its own (for example, if it has opened a window such as the popup you see when a process crashes - and you would not be able to see such window running in the Jenkins service session) and you have access to the slave machine, you can log into it and use a tool like SystemInternals's Process Explorer (available at https://docs.microsoft.com/en-us/sysinternals/downloads/process-explorer ) to find and kill the process. ProcExp is a pretty easy tool to use, is reasonably well known, and great for situations like this.

If you do not have access, you may have to ask the SysAdmins to reboot the slave - it's very likely overkill but if you don't have access to the slave the people you have to ask for help will likely not have much time to help with debugging.

This error may occur due to the performance issue, in such cases we just need to use a loop like to avoid this, because, the current thread has to close before accessing by another process.

You can use the given method to access the file to attach with mail as follows:

using(Attachment attpath = new Attachment(filepath))
{
    //your code to access the attached filepath
    mail.Attachment(attpath);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM