【问题标题】:TFS API: Error thrown while triggering custom build using labelTFS API:使用标签触发自定义构建时引发错误
【发布时间】:2017-04-08 20:46:00
【问题描述】:

我正在尝试使用 TFS API 触发构建。我需要触发基于标签的构建。代码如下:

WorkItemStore workItemStore = tfs.GetService<WorkItemStore>();
Project teamProject = workItemStore.Projects["TFSProjName"];
IBuildServer buildServer = tfs.GetService(typeof(IBuildServer)) as IBuildServer;
IBuildDefinition buildDef = buildServer.GetBuildDefinition(teamProject.Name, "MyTestBuild");
IBuildRequest req = buildDef.CreateBuildRequest();
req.GetOption = GetOption.Custom;
req.CustomGetVersion = "LABC_2.0.389@$/TFSProjName";
buildServer.QueueBuild(req);

在我的构建定义中,提供了构建过程模板的服务器路径(这不是我在上面提供的LabelName 的一部分)。 运行时出现如下错误:

TF215097:为构建定义 \TFSProjName\MyTestBuild 初始化构建时出错:在版本 LABC_2.0.389@$/TFSProjName 的源代码管理中找不到项目 $/TFSProjName/BuildProcessTemplates/NewBuildProcessTemplate.xaml。

当我使用 Visual Studio 触发相同的构建时,它工作正常。我不确定如何明确指示系统检查BuildProcessTemplate,这不是我提供的标签的一部分。

【问题讨论】:

    标签: c# .net tfs msbuild


    【解决方案1】:

    您的问题类似于this case,请查看其中的解决方案:

    我通过将缺少的构建过程模板添加到 我想建立的标签。所以,我基本上用 以下:

    // Check if a label was specified for the build; otherwise, use latest.
    if (!labelName.IsEmptyOrNull())
    {
      // Ensure the build process template is added to the specified label to prevent TF215097.
      AppendBuildProcessTemplateToLabel(tpc, buildDefinition, labelName);
      // Request the build of a specific label.
      buildRequest.GetOption = GetOption.Custom;
      buildRequest.CustomGetVersion = "L" + labelName;
    }
    I created the following method to append the build process template to the label prior to queueing a build.
    
    /// <summary>
    /// Appends the build process template to the given label.
    /// </summary>
    /// <param name="teamProjectCollection">The team project collection.</param>
    /// <param name="buildDefinition">The build definition.</param>
    /// <param name="labelName">Name of the label.</param>
    private static void AppendBuildProcessTemplateToLabel(TfsConnection teamProjectCollection, IBuildDefinition buildDefinition, string labelName)
    {
      // Get access to the version control server service.
      var versionControlServer = teamProjectCollection.GetService<VersionControlServer>();
      if (versionControlServer != null)
      {
        // Extract the label instance matching the given label name.
        var labels = versionControlServer.QueryLabels(labelName, null, null, true);
        if (labels != null && labels.Length > 0)
        {
          // There should only be one match and it should be the first one.
          var label = labels[0];
          if (label != null)
          {
            // Create an item spec element for the build process template.
            var itemSpec = new ItemSpec(buildDefinition.Process.ServerPath, RecursionType.None);
            // Create the corresponding labe item spec element that we want to append to the existing label.
            var labelItemSpec = new LabelItemSpec(itemSpec, VersionSpec.Latest, false);
            // Create the label indicating to replace the item spec contents. This logic will append
            // to the existing label if it exists.
            versionControlServer.CreateLabel(label, new[] {labelItemSpec}, LabelChildOption.Replace);
          }
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-06-21
      • 2016-08-11
      • 2015-04-24
      • 2011-11-27
      • 1970-01-01
      • 2017-09-26
      • 2017-09-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多