TFS 2015 vNext Build - Get specific sources through script - tfs

we are running TFS 2015 Update 3 on premise.
We have a build definition that picks up the latest successful drop from the Gated checkin build to run tests. For theses tests we also need the source code of the same checkin.
If we queue a new build it will get the latest sources, but its possible that these sources are of a different changeset than the last successful drop. Mainly because it can take about 2 minutes before the sources are pulled, if by then a new gated checkin has been completed, the task after the get will get a newer version of the drop than the sources that have been pulled.
Is there a way we can have the build run a script first, say the script that looks for the latest successful build. Then use the changeset number from that build to do the Get Sources of that specific changeset?

We can not prevent the Get source step getting the latest sources, we can only add a Command Line/Batch script or PowerShell step to run script to get the specific changeset version sources. Then copy the specific source to build.
In you scenario, I think it doesn't make sense, as mentioned above, we cannot make sure the changeset number with the latest successful build is the exact changeset your want to get.
Seems the only way is build manually, specific the changeset to build.

Related

Incremental build in TFS 2017 - How to build only code that has changed from the last build? [duplicate]

When we do a TFS Build, can we alter the build output so that the output is limited to only the changes so that deployment payload is reduced ? Example:
When I build a solution, I should only get the changed dlls not all (which includes Microsoft and other 3rd party dlls which are never changed.
Configure CI solution in TFS 2015, and unchecked clean options, Since TFS 2015/2017 always delivered all files - changed and unchanged, but I need only changed. This trick doesn't solve the issue:
Build (TFS Build), only what is changed
Followed a couple of other sources.
IncrementalBuild property in TFSBuild project
Incremental builds in TFS
Applied these tricks to update project with few settings (IncrementalBuild =True, ForceGet=False, SkipInitilizeWorksplace=True, SkipClean=True) under PropertyGroup definition to the end of the TFSBuild.proj file.
But the issue still persists, we are unable to produce only changed binaries in build folder, there is always all files.
Please help me to achieve the desired build output.
Incremental builds only rebuild assemblies that don't depend on changed files. But it does copy all of the project output (subsequent projects that depend on it may depend on these assemblies and files being there).
This causes incremental builds to be much faster, but it doesn't "only deliver the changed files". It always delivers all files whether they are changed or unchanged. On top of this, you could have multiple agents and each agent can have multiple working folders, the incremental build could use any of these as base for the incremental builds, there is no guarantee that the changed files are between your previous build and the current one.
You'll have to implement this feature yourself, it has never been part of MsBuild or TFS Build. It would involve querying TFS for the last drop folder and performing a compare after running an incremental build. Then copying just the changed files and a log of deleted files.
PS: The TFSBuild.proj type builds are very deprecated. They have been surpassed by the XAML builds in TFS 2010 and have been considered "legacy" since then. They have subsequently been surpassed by the new VSTS/Azure DevOps build system which has deprecated the XAML builds. Most of the properties that interact with Source Control are ignored when a TFSBuild.proj project is executed in the Legacy XAML workflow. Instead, the XAML agent takes care of fetching the sources prior to passing control to MsBuild. These new VSTS/Azure Devops build tasks are now also getting YAML support for Git based source control repositories.

can a TFS build task check out a specific commit from a repo instead of checking out complete repo

In our organization we have a requirement to have TFS build task should pull from a specific commit, given a stable commit id build task should check out that particular commit from repo, existing TFS repo build task only checks out latest from given branch, can you please advise if this problem is already solved.
Currently there is no option to do it out-of-the-box in TFS on-premise build pipeline.
You could choose to not sync sources, then the build will not download the repository, and in the beginning of the build add a Command Line task to download only the commit yo want.
About how to disable the get source step in vNext, please refer my reply in this link: Is it able to ignore/disable the first step Get source in vNext Build?
For which kind of git command should use, just the same as in Visual Studio: How do you get a specific version from Git in Visual Studio 2015?

TFS - How to set build definition to build on workspace changes, but NOT download files to workspace?

I have our Solution on CI build. That works.
When dev's check in changes, the solution builds, but only for changes to that solution.
How do I get the build definition to build on changes to OTHER folder changes outside of the solution?
Yes, I can add a workspace in the workspace sources tab. But that means all that code is downloaded on every build.
Our solution has over a dozen dependencies. I would like to trigger a build if any of those dependencies change. We don't need the dependency source code to download into the build workspace at all. That's just pointless.
Yes, we have a folder in TFS for our Nuget Packages. We check them in automatically on build (Thank you TFS).
I could just add the NugetPackage workspace to the solution's workspace list, BUT that would result in every version of every dependency getting downloaded into the build workspace.
How can I trigger a build on a change that I do NOT list in the workspaces list of the build definition?
Btw, we are using TFS 2012
I was hoping the Cloaking feature would allow for this, but if it's cloaked, the automated build does not trigger. The automated build only fires if the workspace folder is set to active. Which also means download every NugetPackage in that same folder!
It's not able to trigger a CI build on a change which not list in the workspaces list of the build definition.
A few other things to know
Make sure the folders you include in your trigger are also included in your mappings on the Repository tab(the same to
workspace mappings).
Source Link
As a workaround you could set clean workspace to false, which will not get other unchanged files every time.
If your build process does not require a clean workspace or
repository, you can significantly reduce the time that is required to
run the build setting this parameter value to False.

Unable to use TFS Build Server with shelvesets

I've been running into problems queuing a build to a TFS Build Server with a specified shelveset. I'm running TFS 2012. I have a visual studio solution with many projects. I'll open the solution, make a change to a few .h header files in a few of the projects, and then make a shelveset for that changeset.
Next, I queue a build to the TFS server. In the build definition, I select the shelveset that I just created. However, when the TFS Build server processes that queued build, it behaves as if it ignored the shelveset. When the compiler processes those projects that have the modified files, the header files in the sources folder do not include the change in the specified shelveset.
Here's the interesting bit. I've watched the files created on the build server as the build is processed. When the sources folders are first created and populated, the changes in the specified shelveset are present. But by the time the build process gets to the relevant project files, the source files have been changed back to the version without the shelveset change.
As far as I can tell, the latest version of the source plus the selected changeset was copied to the build server, but when a build error occurred, the sources were replaced with the latest version only.
Not sure why that happens. When it first occurred it looked as if the sources were changing from 'latest+shelveset' to 'latest' before the build error. Now that I know that's not the case, I'm not going to worry about this any longer.

TFS 2008 Continuous integration MSBUILD on Branch fails on Label

I am attempting to use CI on a Branch of one of my TFS projects. MSBuild only fails when I try to use a Branch. I point the same Build at the "trunk" project it works fine.
The error I receive from the build log:
Task "Label"
Label TeamFoundationServerUrl="http://TFSServer:8080/"
BuildUri="vstfs:///Build/Build/6763"
Name="Test_SF_20090619.1"
Scope="$/MyProject" Recursive=True
Comments="Label created by Team Build"
Version="BuildServer3D143_66"
Child="Replace" Files="$/" C:\Program
Files\MSBuild\Microsoft\VisualStudio\TeamBuild\Microsoft.TeamFoundation.Build.targets(812,5,812,5):
error : No matching items found in $/
in your workspace.
Done executing task "Label" -- FAILED.
Done building target "CoreLabel" in project
"TFSBuild.proj" -- FAILED.
I believe this error is being caused by a lack of source files getting copied to the Build server.
Get task excerpt from build log:
Task "Get"
Get TeamFoundationServerUrl="http://TFSServer:8080/"
BuildUri="vstfs:///Build/Build/6768"
Force=True Overwrite=False
PopulateOutput=False Preview=False
Recursive=True Version="C204806"
Workspace="BuildServer3D143_66"
Done executing task "Get".
This is a full build. There should be about a thousand files listed in the GET.
General Information
TFS 2008
Visual Studio 2008
Established build server (been
running builds for the last year)
Project being branched is a ASP.NET
web stie (2.0 Framework).
Full Build Params
/p:SkipClean=false
/p:SkipInitializeWorkspace=false
/p:ForceGet=true
/p:IncrementalBuild=false
/p:IncrementalGet=false
note: I know IncrementalBuild is redundent but I just wanted to be sure.
Questions:
Are there restrictions on builds off a branch?
Any idea why MSBuild fails to pull files from the branch workspace?
If it's for CI then you're most likely doing an Incremental Get. TFS will only bother to get files it thinks have changed since its last get - e.g. if you delete any files from your server, it will still think you have those files so it won't get them again. In this case you'll need to run the build once with the incremental properties turned off so that it forces a full get of the source. You can do this by overriding the properties in the MSBuild command line box in the Queue Build dialog with:
/p:IncrementalGet=false;ForceGet=true
Another possibility that springs to mind is that the Label task is confused by your branch. It may be that your workspace is set up incorrectly, so check that you're mapping in everything it needs.
I had two issues in this case.
First, the branch security did not give rights to the build service account. I had restricted the branch to our team's Tech Leads and Release Engineers. The build service account needed access as well. What tipped me of was while searching the internet I stumbled upon a posting by someone who had made the same mistake.
The second issue was a little more involved. While cleaning up my build project file, I removed the following section.
<SolutionToBuild Include="$(BuildProjectFolderPath)/../../_stage/MyProject/MySolution.sln">
<Targets></Targets>
<Properties></Properties>
</SolutionToBuild>
Which worked fine on projects I had already built at least once, but if this was a new build, that had not copied source files to the build server, then there would be no files and the build would fail.
Some of you may wonder if my other builds were working either, after all wouldn’t they have old build files. Yes, but I had targets defined that did all the work I actually cared about. So the SolutionToBuild is a little frivalous.

Resources