Вопрос

I'm working on a TFS build definition that kicks-off another build by using the code blogged here: Queue another Team Build when one Team Build succeeds

I'm interested in the first couple of comments at the bottom of the post. Basically, I just want to pass the first build number into the next build.

It was fairly straightforward to change the XAML template to pass an IBuildRequest instead of an IBuildDefinition...

<Sequence.Variables>
    <Variable x:TypeArguments="mtbc:IBuildDefinition" Default="[BuildServer.GetBuildDefinition(BuildDetail.TeamProject, buildChainItem)]" Name="ChainedBuildDefinition" />
    <Variable x:TypeArguments="mtbc:IBuildRequest" Default="[BuildServer.CreateBuildRequest(ChainedBuildDefinition.Uri)]" Name="ChainedBuildRequest" />
    <Variable x:TypeArguments="mtbc:IQueuedBuild" Default="[BuildServer.QueueBuild(ChainedBuildRequest)]" Name="QueuedChainedBuild" />
</Sequence.Variables>

What is proving more tricky is adding the current build number into the ProcessParameters of the new IBuildRequest.

I can see how to add lines of code by using the Default attribute of the <Variable> like above, but it seems each line must return something. But some of the lines I want to run just call a method with no return value e.g. when adding the new element into the ProcessParameters dictionary. Here is what I have tried...

<Sequence.Variables>
    <Variable x:TypeArguments="mtbc:IBuildDefinition" Default="[BuildServer.GetBuildDefinition(BuildDetail.TeamProject, buildChainItem)]" Name="ChainedBuildDefinition" />
    <Variable x:TypeArguments="mtbc:IBuildRequest" Default="[BuildServer.CreateBuildRequest(ChainedBuildDefinition.Uri)]" Name="ChainedBuildRequest" />

    <Variable x:TypeArguments="x:String" Default="[ChainedBuildRequest.ProcessParameters]" Name="NextProcessParameters" />
    <!-- deserialize processparameters string into dictionary -->
    <Variable x:TypeArguments="scg:IDictionary(x:String, x:Object)" Default="[WorkflowHelpers.DeserializeProcessParameters(NextProcessParameters)]" Name="DeserializedProcessParameters" />
    <!-- *** add new parameter, but no return value, so will not work *** -->
    <Variable x:TypeArguments="x:String" Default="[DeserializedProcessParameters.Add(&quot;PreviousBuildNumber&quot;, &quot;1.1.1.1&quot;)]" Name="AddNewParameter" />
    <!-- serialize back into a string -->
    <Variable x:TypeArguments="x:String" Default="[WorkflowHelpers.SerializeProcessParameters(DeserializedProcessParameters)]" Name="SerializedProcessParameters" />
    <!-- *** also no return value, so will not work *** -->
    <Variable x:TypeArguments="x:String" Default="ChainedBuildRequest.ProcessParameters = SerializedProcessParameters" Name="UpdateProcessParameters" />

    <Variable x:TypeArguments="mtbc:IQueuedBuild" Default="[BuildServer.QueueBuild(ChainedBuildRequest)]" Name="QueuedChainedBuild" />
</Sequence.Variables>

So, my first question... is it possible to run lines of code with no return value within the sequence variables?

I'm quite new to these technologies, so may have missed something fundamental. If someone has a different approach to passing the previous build number to the next build, it would also be much appreciated.

Many thanks if you got this far :-)

Это было полезно?

Решение

Thanks to @Jason Stangroome for his original blog post and pointing me towards the InvokeMethod activity. With the help of the excellent WCF & WF Samples for .NET 4, I updated the XAML like this:

<Sequence DisplayName="Queue chained build" sap:VirtualizedContainerService.HintSize="222,146">
    <Sequence.Variables>
        <Variable x:TypeArguments="mtbc:IBuildDefinition" Default="[BuildServer.GetBuildDefinition(BuildDetail.TeamProject, buildChainItem)]" Name="ChainedBuildDefinition" />
        <Variable x:TypeArguments="mtbc:IBuildRequest" Default="[BuildServer.CreateBuildRequest(ChainedBuildDefinition.Uri)]" Name="ChainedBuildRequest" />
        <Variable x:TypeArguments="x:String" Default="[ChainedBuildRequest.ProcessParameters]" Name="NextBuildProcessParameters" />
        <Variable x:TypeArguments="scg:IDictionary(x:String, x:Object)" Default="[WorkflowHelpers.DeserializeProcessParameters(NextBuildProcessParameters)]" Name="DeserializedParameters" />
        <Variable x:TypeArguments="mtbc:IQueuedBuild" Name="QueuedChainedBuild" />
    </Sequence.Variables>

    <sap:WorkflowViewStateService.ViewState>
        <scg:Dictionary x:TypeArguments="x:String, x:Object">
            <x:Boolean x:Key="IsExpanded">True</x:Boolean>
        </scg:Dictionary>
    </sap:WorkflowViewStateService.ViewState>

    <InvokeMethod DisplayName="Add current build number to ProcessParameters" sap:VirtualizedContainerService.HintSize="299.663333333333,127.553333333333" MethodName="Add">
        <InvokeMethod.TargetObject>
            <InArgument x:TypeArguments="scg:IDictionary(x:String, x:Object)">[DeserializedParameters]</InArgument>
        </InvokeMethod.TargetObject>
        <InArgument x:TypeArguments="x:String">["ParentBuildNumber"]</InArgument>
        <InArgument x:TypeArguments="x:Object">[BuildDetail.BuildNumber]</InArgument>
    </InvokeMethod>

    <InvokeMethod DisplayName="Re-serialize ProcessParameters" sap:VirtualizedContainerService.HintSize="299.663333333333,127.553333333333" MethodName="SerializeProcessParameters" TargetType="mtbw:WorkflowHelpers">
        <InvokeMethod.Result>
            <OutArgument x:TypeArguments="x:String">[ChainedBuildRequest.ProcessParameters]</OutArgument>
        </InvokeMethod.Result>
        <InArgument x:TypeArguments="scg:IDictionary(x:String, x:Object)">[DeserializedParameters]</InArgument>
    </InvokeMethod>

    <InvokeMethod DisplayName="Queue Next Build" sap:VirtualizedContainerService.HintSize="299.663333333333,127.553333333333" MethodName="QueueBuild">
        <InvokeMethod.Result>
            <OutArgument x:TypeArguments="mtbc:IQueuedBuild">[QueuedChainedBuild]</OutArgument>
        </InvokeMethod.Result>
        <InvokeMethod.TargetObject>
            <InArgument x:TypeArguments="mtbc:IBuildServer">[BuildServer]</InArgument>
        </InvokeMethod.TargetObject>                      
        <InArgument x:TypeArguments="mtbc:IBuildRequest">[ChainedBuildRequest]</InArgument>
    </InvokeMethod>

    <mtbwa:WriteBuildMessage sap:VirtualizedContainerService.HintSize="200,22" Importance="[Microsoft.TeamFoundation.Build.Client.BuildMessageImportance.High]" Message="[String.Format(&quot;Queued chained build '{0}'&quot;, buildChainItem)]" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces" />
 </Sequence>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top