How to use GetChangeset activity?

Feb 15, 2014 at 10:39 PM
So I'm trying to use the GetChangeset activity for the changeset that is currently being built in the current CI build. However, I'm getting the following:
Exception Message: Error: Object reference not set to an instance of an object.. Stack Trace:    at TfsBuildExtensions.Activities.TeamFoundationServer.GetChangeset.InternalExecute() in d:\code\CodePlex\teambuild2010contrib\CustomActivities\VS2013\Source\Activities\TeamFoundationServer\GetChangeset.cs:line 37
   at TfsBuildExtensions.Activities.BaseCodeActivity.Execute(CodeActivityContext context) in d:\code\CodePlex\teambuild2010contrib\CustomActivities\VS2013\Source\Common\BaseCodeActivity.cs:line 67.  (type FailingBuildException)
Exception Stack Trace:    at TfsBuildExtensions.Activities.BaseCodeActivity.Execute(CodeActivityContext context) in d:\code\CodePlex\teambuild2010contrib\CustomActivities\VS2013\Source\Common\BaseCodeActivity.cs:line 89
   at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
   at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
I'm setting ChangesetId to
Integer.Parse(buildDetail.SourceGetVersion.Replace("C", String.Empty))
I know that buildDetail.SourceGetVersion is not null as I'm writing out the contents in a WriteBuildMessage activity right before calling the GetChangeset activity.

All I really need to do is get the checkin comment....
Mar 4, 2014 at 11:40 AM
Anything on this?
Coordinator
Mar 4, 2014 at 1:12 PM
Yes I started looking at this on the weekend but got sidetracked. If all you want is to get the changeset comment, you should be able to do this without using an activity. What template are you using?

Mike
Mar 5, 2014 at 8:04 PM
Hey Mike. I'm using the Default Template for TFS 2013: TfvcTemplate.12.xaml
Coordinator
Mar 7, 2014 at 10:21 PM
Ok, in general try avoiding custom activities. Here's how you can do it without

Add this reference

xmlns:mtc="clr-namespace:Microsoft.TeamFoundation.Client;assembly=Microsoft.TeamFoundation.Client"

then
    <Sequence DisplayName="Overall build process">
        <!-- Add some variables -->
        <Sequence.Variables>
            <Variable x:TypeArguments="x:String" Name="sourceGetVersion" />
            <Variable x:TypeArguments="mtvc:VersionControlServer" Name="versionControlServer" />
            <Variable x:TypeArguments="mtvc:Changeset" Name="changeset" />
            <Variable x:TypeArguments="mtc:TfsTeamProjectCollection" Name="teamProjectCollection" />
        </Sequence.Variables>
        <mtbac:SetBuildNumber DisplayName="Update build number" BuildNumberFormat="[BuildNumberFormat]" />
        <mtbwa:AgentScope DisplayName="Run on agent" MaxExecutionTime="[AgentSettings.GetValue(Of TimeSpan)(&quot;MaxExecutionTime&quot;, new System.TimeSpan(0,0,0))]" MaxWaitTime="[AgentSettings.GetValue(Of TimeSpan)(&quot;MaxWaitTime&quot;, new System.TimeSpan(4,0,0))]" ReservationSpec="[AgentSettings.CreateAgentReservationSpec()]">
            <mtbac:InitializeEnvironment DisplayName="Initialize environment" />
            <mtbat:TfGetSources DisplayName="Get sources from Team Foundation Version Control" CleanWorkspace="[CleanWorkspace]" CreateLabel="[CreateLabel]" VersionOverride="[GetVersion]" />
            <mtba:AssociateChanges DisplayName="Associate the changesets that occurred since the last good build" UpdateWorkItems="[UpdateAssociatedWorkItems]" />

            <!-- Get SourceGetVersion -->
            <mtbac:GetEnvironmentVariable x:TypeArguments="x:String" Name="[Microsoft.TeamFoundation.Build.Activities.Extensions.WellKnownEnvironmentVariables.SourceGetVersion]" Result="[sourceGetVersion]" />
           
            <!-- Get the TeamProjectCollection so we can get the VC service-->
            <mtbwa:GetTeamProjectCollection Result="[teamProjectCollection]" mtbwt:BuildTrackingParticipant.Importance="None"/>
           
            <!-- Get the VC service-->
            <Assign x:TypeArguments="mtvc:VersionControlServer"  DisplayName="Get the VersionControlServer service" mtbwt:BuildTrackingParticipant.Importance="None" To="[versionControlServer]" Value="[DirectCast(teamProjectCollection.GetService(GetType(VersionControlServer)), VersionControlServer)]"/>
            
            <!-- Get the changeset -->
            <Assign x:TypeArguments="mtvc:Changeset" DisplayName="Get the Changeset" mtbwt:BuildTrackingParticipant.Importance="None" To="[changeset]" Value='[versionControlServer.GetChangeSet(Convert.toInt32(sourceGetVersion.Replace("C", "")))]'/>
           
            <!-- Show the comment -->
            <mtbwa:WriteBuildMessage Message='["Comment: " + changeset.Comment]' Importance="[Microsoft.TeamFoundation.Build.Client.BuildMessageImportance.High]"/>

            <TryCatch DisplayName="Try" mtbwt:BuildTrackingParticipant.Importance="Low">
                <TryCatch.Try>
                    <Sequence DisplayName="Compile, Test and Publish">
Mike
Marked as answer by mikeFourie on 3/7/2014 at 3:21 PM