Detached powershell locks Agent directory

A small post about a problem I ran into the other day on a onpremise TFS.

Ever since the new agentless phase you have the possibility to release your agent to do new work opposed to defining new environments with specific approvers. In the agentless phase I use the manual intervention to wait for approval to pick up the rest of the environment. The scenario in which I use this is to start distributed Tosca UI tests and when they finish the powershell script will call the intervention to continue and upload the testresults. I will write a full blog-post on this topic in the near future.

Keep in mind that the agent can be used for other releases and it’s not guaranteed to give the same agent when your agent phases continuous. To release the pipeline you need to make sure that the actual process isn’t running and so is disconnected. You can do this by starting a new powershell reference to the script you want to run. Your new session will run your script while the old session finishes and returns to the next step in the pipeline.

This will work until you release a second deployment on the same agent while the process is still running in the back. You will notice that the Release artifact directory is locked.

To resolve this you need to change the working directory Start-Process powershell -ArgumentList $argumentList -WorkingDirectory C:\TEMP . This will release the artifact directory and no more unintended locking will occur.

 

I hope this saves you some time and a headache!

 

Leave a Reply

Your email address will not be published. Required fields are marked *