Can move ahead with a console app' task(ie., no longer a labeller as such, but not a problem), will also try an iTask, but not urgent now, thanks
On May 13, 1:15 pm, Badcop666 <[email protected]> wrote: > Craig, I'll try refactoring this as a Task and see what happens > (inside the task block), if you can design a fix for this, I'd > appreciate it if you could sketch it out also for our 1.5.7385.9 copy. > > thx > Andy > > On May 13, 9:59 am, "Craig & Sammi Sutherland" > > > > > > > > <[email protected]> wrote: > > I've had a quick look at this - it is not a problem in your code. There > > appears to be a very nasty bug in the dynamics value code for labellers. > > Somewhere the values are being wiped :-( > > > I tried to figure out what is happening here, but I wasn't able to (at least > > in the time I had spare.) I might try again later on as this problem will > > affect all labellers! > > > Craig > > > -----Original Message----- > > From: [email protected] [mailto:[email protected]] On > > > Behalf Of Badcop666 > > Sent: Friday, 13 May 2011 12:00 a.m. > > To: ccnet-user > > Subject: [ccnet-user] Custom Labeller - Parameters not working, > > dynamicValues problem? > > > Hi, I am storing and incrementing the buildnumber in TFS workitems. > > > Frustratingly close. When I force the build from the web, the > > parameter WorkitemNumber comes through as empty string "" even though > > I enter an existing workitem id. > > > When I run a console harness it works fine - but the problem clearly > > lies in the CCNET interface to this code. > > > I've inherited from LabellerBase as various comments have suggested - > > hence I understood runtime parameters would be sorted for me. It > > appears not so. > > > Any help appreciated. CCNET starts OK and the build runs. I get a TFS > > exception due to attempting to retrieve workitem with ID zero. > > > This is my labeller block currently:- > > > <labeller type="workitemlabeller"> > > <TFSServer>http://tfs:8080</TFSServer> > > <WorkitemID>$[WorkitemNumber]</WorkitemID> > > <WorkitemFieldName>PackageBuildNumber</WorkitemFieldName> > > <BuildType>Package</BuildType> > > </labeller> > > > and parameter:- > > > <parameters> > > <textParameter name="WorkitemNumber"> > > <display>Release Parent Workitem ID</display> > > <required>true</required> > > </textParameter> > > </parameters> > > > Why a text parameter for an int field? I was having trouble with ccnet > > throwing conversion exception - so reverted to this less ideal method. > > > This is my ccnet.workitemlabeller.plugin.dll code:- > > > using System; > > using System.Collections.Generic; > > using System.Linq; > > using System.Text; > > using Exortech.NetReflector; > > using ThoughtWorks.CruiseControl.Core; > > using ThoughtWorks.CruiseControl.Remote; > > using Microsoft.TeamFoundation.Client; > > using Microsoft.TeamFoundation.WorkItemTracking; > > using Microsoft.TeamFoundation.WorkItemTracking.Client; > > using ThoughtWorks.CruiseControl.Core.Label; > > > namespace CCNetWorkitemLabeller > > { > > [ReflectorType("workitemlabeller")] > > public class WorkitemLabeller : LabellerBase > > { > > > private TeamFoundationServer tfs; > > private WorkItemStore store; > > private WorkItem workitem; > > > #region Constructors... > > public WorkitemLabeller() > > { > > //WorkitemFieldName = "PackageBuildNumber"; > > //TFSServer = "http://tfs:8080"; > > //WorkitemID = xxxxx; > > > //Test(); > > } > > #endregion > > > #region Plugin Properties... > > > [ReflectorProperty("TFSServer", Required = true)] > > public string TFSServer{ get; set; } > > > [ReflectorProperty("WorkitemFieldName", Required = true)] > > public string WorkitemFieldName{ get; set; } > > > [ReflectorProperty("WorkitemID", Required = true)] > > // this arrives as a string due to conversion issues... > > public string WorkitemID{ get; set; } > > > [ReflectorProperty("BuildType", Required = true)] > > public string BuildType{ get; set; } > > > #endregion > > > //private int WorkitemID; > > > #region ILabeller Members > > > public override string Generate(IIntegrationResult result) > > { > > int WorkitemFieldValue = 0; > > > int WorkitemID = 0; > > > try > > { > > WorkitemID = Convert.ToInt32(this.WorkitemID); > > } > > catch (Exception E) > > { > > // action? > > } > > > // Connect to TFSServer > > // Attempt to login to the TFS server. > > tfs = TeamFoundationServerFactory.GetServer(TFSServer); > > > // Get the work item service > > store = > > (WorkItemStore)tfs.GetService(typeof(WorkItemStore)); > > > // attempt to retrieve workitem > > > workitem = store.GetWorkItem(WorkitemID); > > workitem.Open(); > > > WorkitemFieldValue = IncrementField(WorkitemFieldName); > > > workitem.History = String.Format("Build Initiated" ); > > > workitem.Save(); > > > return WorkitemFieldValue.ToString(); > > } > > > public string Test() > > { > > > // Connect to TFSServer > > // Attempt to login to the TFS server. > > tfs = TeamFoundationServerFactory.GetServer(TFSServer); > > > // Get the work item service > > store = > > (WorkItemStore)tfs.GetService(typeof(WorkItemStore)); > > > // attempt to retrieve workitem > > > workitem = store.GetWorkItem(Convert.ToInt32(WorkitemID)); > > > workitem.Open(); > > > // check for WorkitemFieldName > > > IncrementField("PackageBuildNumber"); > > IncrementField("ReleaseNoteBuildNumber"); > > > workitem.Save(); > > > // mark Workitem as locked for update > > // get current value of WorkitemFieldName > > // increment, save workitem, return value > > return "1"; > > } > > > public int IncrementField(string WorkitemFieldName) > > { > > int WorkitemFieldValue = 0; > > > if (workitem.Fields.Contains( WorkitemFieldName )) > > { > > if (workitem.Fields[WorkitemFieldName].Value == null) > > { > > workitem.Fields[WorkitemFieldName].Value = 0; > > } > > > WorkitemFieldValue = > > (int)workitem.Fields[WorkitemFieldName].Value; > > > WorkitemFieldValue++; > > > workitem.Fields[WorkitemFieldName].Value = > > WorkitemFieldValue; > > > } > > return WorkitemFieldValue; > > } > > > #endregion > > > #region ITask Members > > > public void Run(IIntegrationResult result) > > { > > result.Label = Generate(result); > > } > > > #endregion > > } > > }
