Builds failing with "The process cannot access the file because it is being used by another process"

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

Builds fail during the Source Code Checkout task, and the agent's logs show the following error:

1 java.lang.RuntimeException: java.io.FileNotFoundException: C:\Windows\TEMP\bamboo-ssh.41538fd5.bat (The process cannot access the file because it is being used by another process)

Cause

The "The process cannot access the file because it is being used by another process" error indicates that there is another process, external to the Bamboo Agent's one, that's trying to access the same file at the same time.

This could happen for many reasons, but the most common cause is that there are two builds running concurrently, checking out the same repository. This wouldn't be a problem, but it becomes one when the two agents are running on the same machine and share the same temporary directory. You can check if that's the case by referring to the agent's logs during a startup timeframe:

<AGENT_ONE_HOME>/logs/atlassian-bamboo.log

1 2 3 4 5 6 7 8 9 2021-10-22 15:36:05,129 INFO [AgentRunnerThread] [lifecycle] ******************************* 2021-10-22 15:36:05,129 INFO [AgentRunnerThread] [lifecycle] * System information * 2021-10-22 15:36:05,129 INFO [AgentRunnerThread] [lifecycle] ******************************* 2021-10-22 15:36:05,192 INFO [AgentRunnerThread] [lifecycle] com.atlassian.bamboo.configuration.SystemInfoImpl@1cf7d169[ ... localHomeDirectory=c:\Bamboo_Agent_One ... tempDir=C:\Windows\TEMP\ ...

<AGENT_TWO_HOME>/logs/atlassian-bamboo.log

1 2 3 4 5 6 7 8 9 2021-10-23 11:26:03,121 INFO [AgentRunnerThread] [lifecycle] ******************************* 2021-10-23 11:26:03,121 INFO [AgentRunnerThread] [lifecycle] * System information * 2021-10-23 11:26:03,121 INFO [AgentRunnerThread] [lifecycle] ******************************* 2021-10-23 11:26:03,188 INFO [AgentRunnerThread] [lifecycle] com.atlassian.bamboo.configuration.SystemInfoImpl@1cf7d169[ ... localHomeDirectory=c:\Bamboo_Agent_Two ... tempDir=C:\Windows\TEMP\ ...

Comparing the two agents' logs, we can see that, even though each one has their own dedicated Home Directory, they still do share the same Temporary Directory, as per the tempDir property value.

Solution

Upon identifying that the above is the cause on your environment, the best approach would be to set each agent on the server to use a different temporary directory. If agents running on the same server have different temporary directories, the "The process cannot access the file because it is being used by another process" error should no longer occur.

Please see the following article for steps on how to change the agents' temporary directories:

Updated on April 11, 2025

Still need help?

The Atlassian Community is here for you.