tfs - How can a Gated check-in be triggered programmatically? -
i getting errors using workspace.checkin command in tfs because files trying check in part of gated build definition. there lots of people asking how override gated check-in using tfs api. different question this: if want perform gated check-in, programmatically? how can trigger in tfs api?
what want is:
- perform normal check-in operation of set of pending changes
- receive information gated build launched
- either subscribe completion event build, or poll build until complete.
- continue if build successful, , changes committed (get resulting changeset if possible)
- stop if build not successful, , report error.
i not find out there answer question; perhaps such edge case i'm 1 crazy enough want this. said, need legitimate. thing can figure need go through lower-level functions of gated check-in process: 1) walk through build definitions see if path of of files coincide of paths in of gated builds. 2) if intersection exists, create shelveset of pending changes 3) queue new build of gated definition using shelveset 4) query build definition , refresh information until build status completed 5) if build successful, unshelve pending changes, , check-in using override.
however, note if these steps, resulting build won't gated build @ all. policy override notifications sent, , way of letting know build performed include such information in policy override comments. there more direct way make other gated build?
prompted post scordo able figure out how this. here code:
//initialize connection server tfsteamprojectcollection tpc = new tfsteamprojectcollection(new uri(serveraddress)); try { tpc.ensureauthenticated(); } catch (exception e) { system.environment.exit(-1); } versioncontrolserver vcserver = tpc.getservice<versioncontrolserver>(); ibuildserver buildserver = tpc.getservice<ibuildserver>(); //. //. //program logic goes here... //. //. //get workspace , respective changes workspace workspace = vcserver.trygetworkspace(localprojectpath); pendingchange[] changes = workspace.getpendingchanges(); //perform check-in bool checkedin = false; //either wait gated check-in or continue asynchronously... bool waitforgatedcheckin = true; //attempt normal check-in try { //first, see policy failures exist, , override them if necessary checkinevaluationresult result = workspace.evaluatecheckin(checkinevaluationoptions.all, changes, changes, "test", null, null); //perform check-in, overrides if necessary, including work item policies //or include additional code comply policies policyoverrideinfo override = null; if (result.policyfailures != null) { override = new policyoverrideinfo("override reason", result.policyfailures); } workspace.checkin(changes, comment, null, null, override); checkedin = true; } catch (gatedcheckinexception gatedexception) { //this exception tells gated check-in required. //first, list of build definitions affected check-in icollection<keyvaluepair<string, uri>> builddefs = gatedexception.affectedbuilddefinitions; if (builddefs.count == 1) { //if 1 affected build definition exists, have need proceed ienumerator<keyvaluepair<string, uri>> buildenum = builddefs.getenumerator(); buildenum.movenext(); keyvaluepair<string, uri> builddef = buildenum.current; string gatedbuilddefname = builddef.key; uri gatedbuilddefuri = builddef.value; string shelvesetspecname = gatedexception.shelvesetname; string[] shelvesettokens = shelvesetspecname.split(new char[] { ';' }); //create build request gated check-in build ibuildrequest buildrequest = buildserver.createbuildrequest(gatedbuilddefuri); buildrequest.shelvesetname = shelvesettokens[0]; //specify name of existing shelveset buildrequest.reason = buildreason.checkinshelveset; //check-in shelveset if successful buildrequest.gatedcheckinticket = gatedexception.checkinticket; //associate check-in //queue build request iqueuedbuild queuedbuild = buildserver.queuebuild(buildrequest); //wait build complete, or continue asynchronously if (waitforgatedbuild) { while (!queuedbuild.build.buildfinished) { //get latest status of build, , pause yield cpu queuedbuild.refresh(queryoptions.process); system.threading.thread.sleep(1000) } if (queuedbuild.build.status == buildstatus.succeeded) { checkedin = true; } } } else { //determine method specifying appropriate build definition //if multiple build definitions affected } } catch (checkinexception checkinexception) { //handle other checkin exceptions such occurring locked files, //permissions issues, etc. } if (checkedin) { //additional logic here, if check-in successful }
Comments
Post a Comment