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:
Get ADOS to run taskkill
automatically before the Get sources step. How?
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.
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