问题
I'm writing a script that will run a build only if there is a change in source code. I need to know whether there is a change since the build last ran. This used to work because the folder would not be deleted, so it was easy to determine whether there was a change, but now everything is deleted everytime the build is run. I thought about using the TFS TF history command to query the last changeset or the last two changesets, but have had issues parsing just the changeset number from the output. I also considered using the changeset command. Is there any command-line parameter that I can use to answer the question, has there been a change since either a date, or a changeset number?
回答1:
To the latest changeset number without local workspace, please use this command:
tf history /collection:"http://server:8080/tfs/Collection" "$/Project" /recursive /stopafter:1 /noprompt /login:domain\user,password
回答2:
excerpt from my batch file to build.
set _aPath="f:\TFS\a"
set _TFPath="c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE"
...
pushd %_aPath%
%_TFPath%\TF.exe history . /r /noprompt /stopafter:1 /Version:W > temp
FOR /f "tokens=1" %%a in ('findstr /R "^[0-9][0-9]*" temp') do set _BuildVersion=10.3.0.%%a
del temp
popd
uses a temp file, but works well.
回答3:
As Andrew mentioned, TFS has continuous integration functionality built-in. However, yes, it's easy to query the changesets since a certain point, be it a date or a changeset. You want to look at the history between that changeset and latest:
tf history <folder> /version:C<changeset>~T /noprompt /recursive
If the only line output is the changeset you queried for, then obviously there have been no changes since that checkin. Otherwise, you will see the additional changesets, one per line.
回答4:
There is an adaptor that can integrate BuildForge and Microsoft Team Foundation Server. Here is the url if you are interested...http://www-304.ibm.com/partnerworld/gsd/solutiondetails.do?&solution=46360&lc=en
The Automatra TFS Adaptor for Rational Build Forge provides Continuous Integration (CI) and reporting capabilities.
The TFS Adaptor further enables CI capabilities at both the TFS Source (Change Set) and WorkItem levels. Out of the box reporting delivers clear Bill of Materials (BOM) reports that can be delivered to downstream consumer of your builds.
Finally, as you must be aware, the strength of Build Forge is its capability to bridge build with deployment (and beyond). Obviously, with these Continuous Integration capabilities you can then move forward with the continuous delivery capability I believe you wish to achieve.
回答5:
My PowerShell script that is called GetVcsRevision.ps1
and located in subfolder of VCS Root:
param (
[string]$PathToTF='C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\TF.exe'
,[Parameter(Mandatory=$true)][string]$Login
,[Parameter(Mandatory=$true)][string]$Password
)
$result = &$PathToTF @("history","/stopafter:1","/recursive","..\*","/login:""$Login"",""$Password""") 2>&1 3>&1
if ($result.GetType().Name -eq "Object[]")
{
<# $result format is:
Changeset User Date Comment
--------- ----------------- ---------- ----------------------------------------
26038 user 24.06.2014 Sample commit comment
$result[2] is:
26038 user 24.06.2014 Sample commit comment
$result[2].Split(" ")[0] is:
26038
#>
$result[2].Split(" ")[0]
}
else
{
"0"
}
It is sending last changeset number to out pipe. If something goes wrong, then this number is 0
.
You can make a function from this script and call it in you build script.
回答6:
My one-line command:
for /f "usebackq tokens=*" %%a in (`tf history . /recursive /noprompt /stopafter:1 /version:T ^| powershell -Command "$input | ? { $_ -imatch '^(\d+)\s+' } | %% { $matches[0].Trim() } | Select-Object -First 1"`) do set TIP_CHANGESET=%%a
after execution TIP_CHANGESET env. variable contains tip changeset
来源:https://stackoverflow.com/questions/10338149/using-tfs-tf-history-to-determine-the-latest-changeset