TFS Build specific changeset and deploy it using the changeset number - tfs

I have a Build Definition to build a solution on my TFS.
This works well, but it always builds the latest version.
How can I force to build a specific changeset from the past?
How can I use/pass this number to the "MSBuild Arguments" to use it there for deployment?

When you queue up the build from Team Explorer, in the Parameters tab one of the Advanced arguments is get version.
Note: I think you need to specify this in the form C123 where 123 is the changeset number.

The answer to your first question is clearly what #Dylan has stated.
To your second part:
The important argument is GetVersion.
Navigate to activity "Run MSBuild for Project" within your Build Process Template, by default this has a value CommandLineArguments equal to
String.Format("/p:SkipInvalidConfigurations=true {0}", MSBuildArguments)
You can change it to something like
String.Format("/p:SkipInvalidConfigurations=true {0} /p:DeployIisAppPath=/changeset/{1}", MSBuildArguments, GetVersion)
and get where you need to go.

If you use the changeset number, then it will only make sense for CI builds, since they typically build a single changeset.
For any other kind of build, I recommend using the build ID, which is unique, and covers the case of a build that builds multiple changesets.

Related

TFS 2015 Build definition - override Build number with variables

We use a nice $(date:yyyy.MM.dd)$(rev:.r) build number format in our day-to-day agile sprints. However, the release must be numbered with a simpler 1.0.0.rev schema.
Ideally, I would like to give the build number as a variable, which would be automatically expanded in the "queue build" dialog, where it would be possible to be overriden. How can it be done?
I tried moving the $(date:yyyy.MM.dd)$(rev:.r) format to a variable, and use that variable in the general tab, and got error 400.
You could directly use Environment variables such as Build.BuildNumber /BUILD_BUILDNUMBER
Using this just equals to the name of the completed build. You can specify the build number format that generates this value on the General tab.
If you just want to generate custom build numbers like 1.0.0.rev schema in TFS Build vNext. You can take a look at below blogs:
Generate custom build numbers in TFS Build vNext
Managing vNext build Version Numbers
This is very simple.
1) Just create a Powershell script like this
$FinalVersion=Some-Function-To-Calculate-Version
$BuildDefName = $Env:BUILD_DEFINITIONNAME
Write-Host "##vso[build.updatebuildnumber]$($BuildDefName)-$($FinalVersion)"
2) In your vNext build definition, for "Build number format" just set it to anything. It doesn't matter because the Build Number will be overwritten.
3) In the same vNext build definition steps, add the first step as a Powershell step, and set your script from step 1 to be executed. You can later customize if you want to pass variables in order to calculate your build number.
4) Queue your build and see the results.

TFS: How to reset BuildDetail.BuildNumber?

Simply, I have created multiple builds in Main Branch. However, BuildDetails.BuildNumber is same and incrementing.
I know if I branch my code, it would reset to 1.
Q: Is it possible to reset this number for each build without creating branches?
Update: The only option I find up till now is to save my BuildNumber in Version.txt, checked into TFS repository. Checkout this during build, get the number, increment it, use it in versioning, and Checkin the file. However, still looking for some better solution.
A bit unclear on what you're after. Let me try to explain how build numbers work:
Build "numbers" are generated using the Build Number Format build definition parameter, which by default is $(BuildDefinitionName)_$(Date:yyyyMMdd)$(Rev:.r). The $(Rev:.r) part automatically increments, and resets back to 1 when the day change (all this happens separately for each build definition). AFAIK there's no way to reset $(Rev:.r), nor should there be, because that would case multiple builds with the same build number, which would be confusing.
Rather than having your version number stored in source control you can use the build number generated by TFS.
If you change the format from "$(BuildDefinitionName)_$(Date:yyyyMMdd)$(Rev:.r)" to something like "$(BuildDefinitionName)_1.5.$(YY)$(ddd)$(Rev:.r)" then you can set it as part of the build definition.
You can then parse out this number and use it to version your application, and change it how you like by branch, or whatever.

build latest sources with a changeset in tfs

I want to get the changeset of last good build of a given build definition and then build for that changeset. Is there any way to achieve this by modifying the defaultTemplate? Maybe I can use an In Argument to pass the build definition name to the build process template.
Any help/direction/insight is appreciated. Thanks. :)
Not sure what you mean by "Latest Sources plus a Changeset", Latest Sources by definition includes all changesets.
In the default template there's an argument "GetVersion" under advanced you can specify a changeset to build.
According to the description this just overrides the iBuildDetail.SourceGetVersion.

How to do an Automated build in TFS 2010 by a label

I have my automated builds working but I want to be able to go back to a specifc labeled version and build from that source. The build definition under "Process" has the item "Get Version" but this is for a specific changeset which seems fairly useless. Does anyone have any idea how I would go about doing this?
The Get Version accepts what TFS calls an versionspec which can be either a changeset or a label. To specify a label just prefix it with an L.
LMyLabel
#Dylan Smith: Is right. You can specify in the advanced Get Version parameter the label by: LmyLabel or CmyChangeset in order to queue a specific version. There are other options like date, "W" (Version last fetched to your workspace), or "T" (latest version) as well.
For more information: Building a Specific Version with Team Build 2008
During your build process, label the code (In my case I use the build number as part of the label).
Then when you want to build a specific labeled version, pass the label to the build script, get the code from the library by label, build the code, and deploy.
See http://msdn.microsoft.com/en-us/library/fx7sdeyf.aspx for how to get a labeled version.

Redeploying historical builds through TFS

Does TFS offer a way to save, track, and later redeploy builds by build number, or can you only deploy .dlls compiled from the current codebase? I'm looking for functionality similar to what you find in Changeman DS.
Yes. Every build definition in Team Build has a "retention policy" that defines how many historical builds should be kept, depending on certain criteria. You can also mark individual builds as "keep indefinitely." Kind of like a Tivo...
Example walkthru with screenshots: http://blogs.msdn.com/buckh/archive/2007/08/14/tfs-2008-a-basic-guide-to-team-build-2008.aspx
If you need to recover a build that has already been deleted from the drop share, you can do that too -- you'll just have to rebuild it. Simply queue up the build definition, but before you hit Go, type /p:GetVersion="XXX" in the text area at the bottom labeled "additional MSBuild arguments." XXX can be any versionspec, just like you'd use at the tf.exe command line. Examples might be "C12345" or "D1/10/2010" or "LsomeLabel".

Resources