简体   繁体   中英

Azure DevOps Server: How to prevent 'Access to path is denied' when initalizing a job?

I am using Azure DevOps Server 2019 (ADOS for short, installed on-premises) to run end to end tests based on Selenium in C#.

Every now and then a build ends badly without properly stopping the chromedriver.exe process used by my Selenium tests. As a result, the subsequent build fails at the Initialize Job step with an error that looks like this:

One or more errors occurred. (Access to path 'C:...\chromedriver.exe' is denied.)

What I understand from this is that because chromedriver.exe is still running ADOS cannot delete its .exe file when it tries to clean the working folder at the start of the build run.

I've tried disabling the Clean feature of the Get sources step definition but that only shifted the error a bit forward to the Checkout step.

To resolve the problem I am forced to manually RDP into my agent machine, taskkill /IM chromedriver.exe /F and re-run the failed build.

My question is - How can I prevent the access denied error? I've thought of these approaches but I'm not sure which is practical:

  1. Get ADOS to run taskkill automatically before the Get sources step. How?

  2. Make the agent have higher privileges so it can delete chromedriver.exe even when its process is still running. Again, how?

If your assumption is correct:

What I understand from this is that because chromedriver.exe is still running ADOS cannot delete its .exe file when it tries to clean the working folder at the start of the build run.

Make sure you are using the driver.close() as well as the driver.quit() methods at the end of every test.

Use teardown to make sure it will always happen.

EDIT:

As OP commented:

when I cancel the ADOS build, the test step is terminated abruptly and the teardown step is not executed.

My recommendation is to an atexit method.

For C# Use ProcessExit Event (credit to @Fredrik Mörk 's answer )

For Python use atexit

I've come up with a solution based on ADOS Pipelines' functionality. After my Visual Studio Test task I've added a Command Line task and configured it like so:

  1. The script is ' taskkill /IM chromedriver.exe /F '.
  2. Under Control Options I've set:
    • Run this task to 'Custom conditions'
    • Custom condition to ' canceled() '
    • Continue on error checked.

This way, whenever my build is cancelled manually, all instances of the chromedriver.exe process are terminated, clearing the way for subsequent builds to run.

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