Build service cannot delete Android project folder because of adb.exe - tfs

We are building a few Xamarin projects on our TFS build server, and see the following error from time to time:
Exception Message: The process cannot access the file
'D:\Builds\135\1892\Sources\Component\OurService.Android' because it
is being used by another process. (type IOException) Exception Stack
Trace: at
Microsoft.TeamFoundation.Common.FileSpec.DeleteDirectoryLongPath(String
path, Boolean recursive, Boolean followJunctionPoints) at
Microsoft.TeamFoundation.Common.FileSpec.DeleteDirectoryLongPath(String
path, Boolean recursive, Boolean followJunctionPoints) at
Microsoft.TeamFoundation.Common.FileSpec.DeleteDirectoryLongPath(String
path, Boolean recursive, Boolean followJunctionPoints) at
Microsoft.TeamFoundation.Build.Workflow.Activities.DeleteDirectory.Execute(CodeActivityContext
context) at
System.Activities.CodeActivity.InternalExecute(ActivityInstance
instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at
System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor
executor, BookmarkManager bookmarkManager, Location resultLocation)
Inner Exception Details:
Exception Message: The process cannot access the file because it is
being used by another process (type Win32Exception)
It happens during clean workspace where it starts by deleting the source directory and only for the empty Android project folder. Looking at Resource Monitor it reveals it to be C:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe that keeps a lock on the folder. The lock seems to be release after some time or by restarting the server.
We are using TFS 2015 Update 3 XAML builds and the build server has VS 2015 Update 3 with Xamarin 4.2.2.6 installed. We see no issues locally on our developer machines, but that could just be because we are not deleting the source folders on a regular basis.
Any suggestion on how to get around this issue?

Mare sure that specifical file is not Read-Only, and also check if your Build service account has enough permission such as running as a local admin.
Usually this kind of issue will be fixed by cleaning team foundation cache on the build agent machine .

This seems to have been fixed by some Xamarin update as we have not seen it for a while now.

Related

Build failing on TFS2013 witht the workspace permissions error

We have verified the solution file is exist in the folder also it's mapped in to the local workspace.
Source setting on the build directory set as below. Also have confusion in setting build agent folder. Reffered few blogs but nothing works.
Source control folder
$/ABC Project/CAP/Spon/SponGroupP/Sponsor
Build agent folder
$(SourceDir)
Other Errors and Warnings
2 error(s), 0 warning(s)
**No matching items found in $/ABC Project/CAP/Spon/SponGroupP/Sponsor in your workspace, or you do not have permission to access them.**
Exception Message: One or more errors occurred while attempting to create a Label. (type LabelException)Exception Stack Trace: at System.Activities.Statements.Throw.Execute(CodeActivityContext context) at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
Can someone help me out on this please.
Update:
Your file path is too long, there are two Sponsor in your folder structure. Besides, try to tweak the source control path in TFS server, which may do the trick. Details take a look at this question: 'CSC:CSC(0,0): Error CS2001: Source file [file] could not be found.' when running a gated check in (C#)
First try to turn the label sources in Process--TF Version Control of your XAML build definition from True(default value) to False
This will narrow down if the issue is related to creating label or not. If the build succeed, then you should double check if your build service account have have appropriate permissions to create labels.

Waiting for an available agent / Waiting for an agent to be requested

(26.07.2016)I am using TFS2015 Update3 in a VM.
When I try to queue a build through the web interface or from Team Explorer, I get the following.
Then I restart all services related to TFS in services.msc and then after some time it starts working again.
So this happens too often.
I have a custom pool running:
Is there a way to debug this behaviour?
Examining the Log files
Link to Worker log file
Link to Agent log file
Exception occurs in this order here:
Checking if artifacts directory exists C:\workspaces\agent\_work\2\a
Deleting artifacts directory
System.ComponentModel.Win32Exception (0x80004005): The directory is not empty
at Microsoft.TeamFoundation.Common.FileSpec.DeleteDirectoryLongPath(String path, Boolean recursive, Boolean followJunctionPoints)
The weird thing is, queueing new build works most of the time, this happens only sporadically
It could be, that I have opened a file from that folder in notepad with many tabs open. Will observe if this issue persists and report.
If this is happening sporadically, it might a long path exists here in artifacts:
C:\workspaces\agent_work\2\a
Or, there was a cancelled build which left the artifact directory half cleaned which exposed a bug in cleaning.
The 2.x agent isn't subject to long paths (net core) but only works with 2017+:
https://github.com/Microsoft/vsts-agent
We can troubleshoot but it would be good to get to 2017+ (2018 QU3 is out) with a 2.x agent.
If that's not an option, message me and we can dig into what I think is a cancel / state bug.

Error while building using TFS build server

This error I am getting when I am running build using TFS, and I don't have any clue as to what to do:
I am using TFS 2013.
Exception Message: TF201077: The work item type Bug cannot be found. It may have been renamed or destroyed. (type WorkItemTypeDeniedOrNotExistException)
Exception Stack Trace: at System.Activities.Statements.Throw.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
Also I am getting this warning:
TF270003: Failed to copy. Ensure the source directory C:\Builds\2\Test\Test-CI\bin exists and that you have the appropriate permissions.
Most the time I see TF270003: Failed to copy. Ensure the source directory C:\Builds\2\Test\Test-CI\bin exists and that you have the appropriate permissions. it sets off alarm bells about the solutions/projects. Generally it means someone has checked in the bin or obj folders which then leads to this error when build compiles things and tries to overwrite dlls in the bin folder with new copies but those are marked as read only when they are pulled into the build working directory. If you have bin or obj folders checked into tfs delete them and rebuild.

TFS Incremental build error - Unable to perform the get operation because the file already exists locally

I'm trying to enable incremental build of my VS solution. In the GUI for xaml build process template, I set "Clean Workspace" to "None" and added /p:IncrementalBuild=True as an MSBuild argument. I then checked in changes to a file, but when I run my TFS build, I immediately get the following error:
Unable to perform the get operation because the file already exists locally
Exception Message: One or more errors occurred while performing a Get operation. (type GetException)
Exception Stack Trace: at Microsoft.TeamFoundation.Build.Workflow.Activities.SyncWorkspaceInternal.ThrowIfErrorsOccurred.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
I believe TFS gets my file but cannot overwrite the existing file on the build agent and errors out. How can I force it to overwrite the file?
The file is writable. When there's a writable file, get will not overwrite it unless the /overwrite option is used. However, you would need to figure out how the file is becoming writable. You may want to go back to the default option of creating a new workspace, running a build with verbose logs, and see what is making the file writable.
In XAML Build, you can add a GetOptions input for the SyncWorkspace activity.
<mtbwa:SyncWorkspace _locID="Activity037" _locAttrData="DisplayName" DisplayName="Get Workspace" VersionOverride="[GetVersion]" Workspace="[Workspace]" GetOptions="[Microsoft.TeamFoundation.VersionControl.Client.GetOptions.Overwrite]">
See DefaultTemplate.11.1.xaml as a go-by.
TfvcTemplate.12.xaml doesn't expose a way to do it.

Builds fails in the gate, but builds fine locally

My changeset keeps failing the dev gate build.
Unfortunately TFS build does not give me any clues, this is the only exception I got:
Exception Message: MSBuild error 1 has ended this build. You can find more specific information about the cause of this error in above messages. (type BuildProcessTerminateException)
Exception Stack Trace: at System.Activities.Statements.Throw.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
I have Google'd it and for those refering to blogs:
I don't use Fakes
Server has enough memory
Server has TFS 2012 + update 1
Solved!
This entry in the common property group of one of my test projects was the issue:
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
This element must be removed in test projects (MS Test).
I verified it with the other 4 test projects, and they didn't have this entry.
I don't know why this entry is not accepted, but my gate accepts check-ins again ;-)

Resources