TFS2018为什么架子集名称为空? [英] TFS2018 why is shelveset name empty?

查看:56
本文介绍了TFS2018为什么架子集名称为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用TFS2018手动对构建进行排队时,架子集名称并不会在所有情况下都显示源分支名称.有时填写,有时不填写.由于我正在为源分支选择构建变量 $(Build.SourceBranch) $(Build.SourceBranchName)

When queue-ing a build manually using TFS2018 the shelveset name is not showing the source branch name in all cases. Sometimes it is filled out sometimes not. Since I am picking up build variables for the source branch $(Build.SourceBranch) $(Build.SourceBranchName)

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

They will be empty if the Shelveset name is empty.

在创建构建定义时,是否可以使用API​​将货架集名称默认设置为源分支?

Is it possible to set the shelveset name default as the sourcebranch using the API when creating the build definition?

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

Is there another build variable that I can use to get the source path for the currently built solution?

UPDATE因此,我正在尝试使用build api更新源分支.但是,当我打电话给我

UPDATE So I am trying to update the source branches using the build api. However when called I get a

{StatusCode:405,ReasonPhrase:不允许使用方法",版本:1.1,内容:System.Net.Http.StreamContent,标头: { 语法:无快取 X-TFS-ProcessId: ActivityId: X-TFS会话: X-VSS-E2EID: X框架选项:SAMEORIGIN X-VSS-UserData ::用户 持久验证:true LFS验证: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我们的三美客车DEM海军STA UNI COM INT PHY ONL FIN PUR LOC CNT" 服务器:Microsoft-IIS/10.0 X-AspNet版本:4.0.30319 X-Powered-by:ASP.NET 内容长度:93 允许:GET 内容类型:application/json;字符集= utf-8 过期:-1 }}

{StatusCode: 405, ReasonPhrase: 'Method Not Allowed', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { Pragma: no-cache X-TFS-ProcessId: ActivityId: X-TFS-Session: X-VSS-E2EID: X-FRAME-OPTIONS: SAMEORIGIN X-VSS-UserData: :user Persistent-Auth: true Lfs-Authenticate: NTLM X-Content-Type-Options: nosniff Cache-Control: no-cache Date: Fri, 09 Mar 2018 14:37:16 GMT P3P: CP="CAO DSP COR ADMa DEV CONo TELo CUR PSA PSD TAI IVDo OUR SAMi BUS DEM NAV STA UNI COM INT PHY ONL FIN PUR LOC CNT" Server: Microsoft-IIS/10.0 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Content-Length: 93 Allow: GET Content-Type: application/json; charset=utf-8 Expires: -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)
                {

                }

            }
        }

推荐答案

您应使用

You should use Queue a build api to set SourceBranch, for example:

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\"}"
}

如果要选择要构建的货架集,则api如下所示:

If you want to choose a shelveset to build, then the api looks like below:

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\"}"
    }

这篇关于TFS2018为什么架子集名称为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆