TFS2018为什么shelveset名称为空?

时间:2018-03-02 11:33:32

标签: tfs azure-devops tfvc

使用TFS2018手动排队构建时,搁置集名称在所有情况下都不显示源分支名称。有时它有时候没有填写。因为我正在为源分支选择构建变量  $(Build.SourceBranch) $(Build.SourceBranchName)

如果Shelveset名称为空,它们将为空。

enter image description here

在创建构建定义时,是否可以使用API​​将搁置集名称default设置为sourcebranch?

我是否可以使用另一个构建变量来获取当前构建的解决方案的源路径?

更新所以我试图使用build api更新源分支。但是当我打电话给我时

{StatusCode:405,ReasonPhrase:'Method Not Allowed',版本:1.1,内容:System.Net.Http.StreamContent,标题: {   Pragma:没有缓存   X-TFS-的ProcessID:   ActivityId:   X-TFS-会议:   X-VSS-E2EID:   X-FRAME-OPTIONS:SAMEORIGIN   X-VSS-UserData :: user   Persistent-Auth:是的   Lfs-Authenticate:NTLM   X-Content-Type-Options:nosniff   缓存控制:无缓存   日期:星期五,2018年3月9日14:37:16 GMT   P3P:CP =“CAO DSP COR ADMa DEV CONo TELo CUR PSA PSD TAI IVDo我们的SAMi BUS DEM NAV STA UNI COM INT PHY ONL FIN PUR LOC CNT”   服务器:Microsoft-IIS / 10.0   X-AspNet-Version:4.0.30319   X-Powered-By:ASP.NET   内容长度:93   允许:GET   Content-Type:application / json;字符集= utf-8的   到期:-1 }}

以下代码......

internal void UpdateSourceBranches(List<BuildDefinition> defs)
        {
            using (var handler = new HttpClientHandler { Credentials = new NetworkCredential(tfsUser, tfsPass) })
            using (var client = new HttpClient(handler))
            {
                try
                {
                    client.BaseAddress = new Uri(tfsServer);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    foreach (var def in defs)
                    {
                        var buildId = def.Id;
                        var sourceBranch = $"$/{def.Repository.Name}/{def.Project.Name}";
                        var parameters = new Dictionary<string, string> { { "BuildConfiguration", "release" },
                        { "BuildPlatform", "x86|x64|ARM" },
                        { "system.debug", "true" }
                    };

                        var jsonParams = JsonConvert.SerializeObject(parameters);

                        var content = new FormUrlEncodedContent(new[]
                        {
                            new KeyValuePair<string, string>("id", buildId.ToString()),
                            new KeyValuePair<string, string>("sourceBranch", sourceBranch),
                            new KeyValuePair<string, string>("parameters", jsonParams)
                        });

                        var response = client.PostAsync($"DefaultCollection/{def.Repository.Name}/_apis/build/builds?api-version=3.0-preview.1", content);
                        var s = response.Result;
                    }                  
                }
                catch (Exception ex)
                {

                }

            }
        }

1 个答案:

答案 0 :(得分:1)

您应该使用Queue a build api来设置SourceBranch,例如:

POST http://TFS2018:8080/tfs/DefaultCollection/{project}/_apis/build/builds?api-version=2.0

Content-Type: application/json

{
  "definition": {
    "id": 47
  },
  "sourceBranch":"$/CeceScrum/TestCaseProject",
  "parameters":"{\"BuildConfiguration\":\"release\",\"BuildPlatform\":\"any cpu\",\"system.debug\":\"false\"}"
}

如果你想选择一个shelveset来构建,那么api如下所示:

POST http://TFS2018:8080/tfs/DefaultCollection/{project}/_apis/build/builds?api-version=2.0

    Content-Type: application/json

    {
      "definition": {
        "id": 47
      },
      "sourceBranch":"ceceShelveset;domain\\username",
      "parameters":"{\"BuildConfiguration\":\"release\",\"BuildPlatform\":\"any cpu\",\"system.debug\":\"false\"}"
    }