TFS - 链接生成 - 如何将信息从一个生成传递到下一个生成

本文关键字:一个 下一个 链接 TFS 信息 | 更新日期: 2023-09-27 18:33:09

我正在研究一个 TFS 生成定义,该定义使用此处博客的代码启动另一个生成: 当一个团队生成成功时,将另一个团队生成排队

我对帖子底部的前几条评论感兴趣。 基本上,我只想将第一个内部版本号传递到下一个版本中。

将 XAML 模板更改为传递IBuildRequest而不是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>

事实证明,更棘手的是将当前内部版本号添加到新IBuildRequestProcessParameters中。

我可以看到如何使用<Variable>Default 属性添加代码行,如上所示,但似乎每一行都必须返回一些内容。但是我想运行的一些行只是调用一个没有返回值的方法,例如,将新元素添加到ProcessParameters字典中时。这是我尝试过的...

<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>

所以,我的第一个问题...是否可以在序列变量中运行没有返回值的代码行?

我对这些技术很陌生,所以可能错过了一些基本的东西。如果有人有不同的方法将以前的内部版本号传递到下一个内部版本,也将不胜感激。

非常感谢,如果你走到了这一步:-(

TFS - 链接生成 - 如何将信息从一个生成传递到下一个生成

感谢 @Jason Stangroome 的原始博客文章,并指出我指向 InvokeMethod 活动。在优秀的 .NET 4 WCF 和 WF 示例的帮助下,我像这样更新了 XAML:

<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>