tfs2010 - How to retrieve TestRunId by build number using TFS api? -
we need run tests , publish results in custom continousintegration environment. mstest used testing, use commandline execution of tfs build. after executing tests/build using tfsbuild.exe, buildnumber , updatedbuildnumber.
c:\program files (x86)\microsoft visual studio 10.0\vc>tfsbuild start "tfsurl" "teamprojectname" "builddefinitionname" microsoft (r) tfsbuild version 10.0.0.0 microsoft visual studio v10.0 copyright (c) microsoft corporation. rights reserved. build number: 36399 updated build number: xyz_20140405.1 succeeded
i use updatedbuildnumber query tfs , builduri.
uri tfsuri = new uri("tfsurl"); tfsteamprojectcollection _tfs = new tfsteamprojectcollection(tfsuri); ibuildserver tfsbuildserver = _tfs.getservice<ibuildserver>(); ibuilddefinitionspec buildspec = tfsbuildserver.createbuilddefinitionspec("teamprojectname"); ibuilddetail builddetail = tfsbuildserver.getbuild(buildspec, "xyz_20140405.1", null, queryoptions.all);
the builddetail has builduri passed retrieve testrunid, using testresults (trx) file can exported (tcm command)
itestmanagementservice test_service = (itestmanagementservice)_tfs.getservice(typeof(itestmanagementservice)); itestmanagementteamproject _testproject = test_service.getteamproject("teamprojectname"); var testruns = _testproject.testruns.bybuild(builddetail.uri); int testrunid= 0; if (builddetail.buildfinished) { foreach (itestrun item in testruns) { testrunid= item.id; } }
this code doesn't work always. getting build uri works testrunid fails saying enumertion yeilded no results. can suggest how testrunid using buildnumber or updatedbuildnumber?
i had same problem getting itestrun
builduri
. found 2 ways solve worked me:
// after getting build details, test runs , compare matching properties: ibuilddetail builddetail = tfsbuildserver.getbuild(buildspec, "xyz_#", null, queryoptions.all); // test run title , build number, surprisingly match: itestrun testrun = _testproject.testruns.query("select * testrun").where(x => x.title == builddetail.buildnumber).single(); // test run finish time: itestrun testrun = _testproject.testruns.query("select * testrun").where(x => x.lastupdated == builddetail.lastchangedon).single(); int testrunid = testrun.id;
Comments
Post a Comment