<bdo id='jclSJ'></bdo><ul id='jclSJ'></ul>

<small id='jclSJ'></small><noframes id='jclSJ'>

      1. <tfoot id='jclSJ'></tfoot>
      2. <legend id='jclSJ'><style id='jclSJ'><dir id='jclSJ'><q id='jclSJ'></q></dir></style></legend>

      3. <i id='jclSJ'><tr id='jclSJ'><dt id='jclSJ'><q id='jclSJ'><span id='jclSJ'><b id='jclSJ'><form id='jclSJ'><ins id='jclSJ'></ins><ul id='jclSJ'></ul><sub id='jclSJ'></sub></form><legend id='jclSJ'></legend><bdo id='jclSJ'><pre id='jclSJ'><center id='jclSJ'></center></pre></bdo></b><th id='jclSJ'></th></span></q></dt></tr></i><div id='jclSJ'><tfoot id='jclSJ'></tfoot><dl id='jclSJ'><fieldset id='jclSJ'></fieldset></dl></div>

      4. 如何通过 VSTS REST API 创建构建定义

        How to create Build Definitions through VSTS REST API(如何通过 VSTS REST API 创建构建定义)

          <bdo id='5yXiA'></bdo><ul id='5yXiA'></ul>

            <i id='5yXiA'><tr id='5yXiA'><dt id='5yXiA'><q id='5yXiA'><span id='5yXiA'><b id='5yXiA'><form id='5yXiA'><ins id='5yXiA'></ins><ul id='5yXiA'></ul><sub id='5yXiA'></sub></form><legend id='5yXiA'></legend><bdo id='5yXiA'><pre id='5yXiA'><center id='5yXiA'></center></pre></bdo></b><th id='5yXiA'></th></span></q></dt></tr></i><div id='5yXiA'><tfoot id='5yXiA'></tfoot><dl id='5yXiA'><fieldset id='5yXiA'></fieldset></dl></div>

            <legend id='5yXiA'><style id='5yXiA'><dir id='5yXiA'><q id='5yXiA'></q></dir></style></legend>

                  <small id='5yXiA'></small><noframes id='5yXiA'>

                    <tbody id='5yXiA'></tbody>
                • <tfoot id='5yXiA'></tfoot>
                  本文介绍了如何通过 VSTS REST API 创建构建定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我目前正在通过 bitbucket -> vsts -> azure 自动化 CI/CD 配置.

                  I'm currently working on automating CI/CD configurations through bitbucket -> vsts -> azure.

                  我的理想结果是能够将我的配置值复制粘贴(或手动输入)到它们各自的控制台程序中,并让应用程序配置整个 CI/CD 考验,而无需单击所有 Web 界面.现在可以在 Bitbucket 和 Azure 中使用,但通过 REST API 创建 VSTS CI/CD 配置被证明是困难的.

                  My ideal result is to be able to copy paste (or manually enter) my configuration values into their respective console programs and have the applications configure the whole CI/CD ordeal without having to click through all the web interfaces. It's now possible in Bitbucket and Azure, but creating the VSTS CI/CD configurations through REST API is proving to be difficult.

                  Azure 资源 和 Bitbucket 配置目前是通过一个简单的 .NET 控制台应用程序创建的到 REST API.基本上复制粘贴(或手动输入)所有值(azure 输入值/bitbucket 输入值) 到控制台应用程序,它将在 5 分钟内配置所有内容.

                  Azure resources and Bitbucket configurations are currently created through a simple .NET console application that talks to the REST APIs. Basically copy paste (or manually enter) all the values (azure input values / bitbucket input values)into the console application and it will configure everything within 5 minutes.

                  现在我面临着尝试在 VSTS 中自动化构建配置和发布配置的困难部分.Microsoft Docs 在 VSTS 客户端库的文档.

                  Now I face the harder part of trying to automate build configurations and release configurations in VSTS. Microsoft Docs isn't great on the documentation of VSTS client libraries.

                  老实说,我不知道如何创建构建定义 通过 API 或客户端库.

                  I'm honestly at a loss for how I can create a build definition through the API or Client Library.

                  • BuildHttpClient 有三种我可以使用的方法:

                  • The BuildHttpClient has three methods I can work with:

                  public virtual Task<BuildDefinition> CreateDefinitionAsync(BuildDefinition definition, Guid project, int? definitionToCloneId = null, int? definitionToCloneRevision = null, object userState = null, CancellationToken cancellationToken = default(CancellationToken));   
                  public virtual Task<BuildDefinition> CreateDefinitionAsync(BuildDefinition definition, int? definitionToCloneId = null, int? definitionToCloneRevision = null, object userState = null, CancellationToken cancellationToken = default(CancellationToken));    
                  public virtual Task<BuildDefinition> CreateDefinitionAsync(BuildDefinition definition, string project, int? definitionToCloneId = null, int? definitionToCloneRevision = null, object userState = null, CancellationToken cancellationToken = default(CancellationToken));
                  

                • BuildDefinition 具有以下属性.

                  namespace Microsoft.TeamFoundation.Build.WebApi    
                  { 
                  [DataContract]    
                  public class BuildDefinition : BuildDefinitionReference
                      {
                          public BuildDefinition();
                  
                          public List<string> Tags { get; }
                          public PropertiesCollection Properties { get; }
                          public List<RetentionPolicy> RetentionRules { get; }
                          public List<Demand> Demands { get; }
                          public IDictionary<string, BuildDefinitionVariable> Variables { get; }
                          public List<BuildTrigger> Triggers { get; }
                          public ProcessParameters ProcessParameters { get; set; }
                          public BuildRepository Repository { get; set; }
                          public List<BuildOption> Options { get; }
                          public List<BuildDefinitionStep> Steps { get; }
                          public bool BadgeEnabled { get; set; }
                          public int JobTimeoutInMinutes { get; set; }
                          public BuildAuthorizationScope JobAuthorizationScope { get; set; }
                          public string DropLocation { get; set; }
                          public string Description { get; set; }
                          public string Comment { get; set; }
                          public string BuildNumberFormat { get; set; }
                          public Build LatestBuild { get; }
                          public Build LatestCompletedBuild { get; }
                      }
                   }
                  

                • 如您所见,构建定义的最重要属性是只读的.

                  As you can see, the most important properties of a build definition are read-only.

                  如何通过 REST API 创建构建定义?是否有更好的 VSTS 替代方案可以让我这样做?

                  How do I go about creating a build definition through the REST API? Are there better alternatives to VSTS that will allow me to do this?

                  推荐答案

                  REST API 的格式 创建构建定义如下:

                  The format for the REST API to create a build definition as below:

                  POST https://{account}.visualstudio.com/{project}/_apis/build/definitions?api-version=5.0-preview.6
                  

                  应用程序/json 示例:

                  application/json example:

                  {
                      "process": {
                          "phases": [
                              {
                                  "steps": [
                  
                                  ],
                                  "name": "Phase 1",
                                  "refName": "Phase_1",
                                  "condition": "succeeded()",
                                  "target": {
                                      "executionOptions": {
                                          "type": 0
                                      },
                                      "allowScriptsAuthAccessOption": false,
                                      "type": 1
                                  },
                                  "jobAuthorizationScope": "projectCollection",
                                  "jobCancelTimeoutInMinutes": 1
                              }
                          ],
                          "type": 1
                      },
                      "repository": {
                          "properties": {
                              "cleanOptions": "0",
                              "labelSources": "0",
                              "labelSourcesFormat": "$(build.buildNumber)",
                              "reportBuildStatus": "true",
                              "gitLfsSupport": "false",
                              "skipSyncSource": "false",
                              "checkoutNestedSubmodules": "false",
                              "fetchDepth": "0"
                          },
                          "id": "4ba24767-e5a6-4987-80cc-ebaeca01fdbc",
                          "type": "TfsGit",
                          "name": "product1",
                          "url": "https://marinaliu.visualstudio.com/Git2/_git/product1",
                          "defaultBranch": "refs/heads/master",
                          "clean": "false",
                          "checkoutSubmodules": false
                      },
                      "processParameters": {},
                      "drafts": [],
                      "queue": {
                          "id": 324,
                          "name": "ownPC",
                          "pool": {
                              "id": 23,
                              "name": "ownPC"
                          }
                      },
                      "name": "definitionCreatedByRESTAPI",
                      "type": "build",
                      "queueStatus": "enabled"
                  }
                  

                  要在 C# 中使用 REST API,您可以进行如下转换:

                  To use the REST API in C#, you can convert as below:

                  var personalaccesstoken = "PAT";
                  var base64Token = Convert.ToBase64String(Encoding.ASCII.GetBytes($":{personalaccesstoken}"));
                  HttpClient client = new HttpClient();
                  client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", base64Token);
                  
                  var requestMessage = new HttpRequestMessage(HttpMethod.Post, "https://account.visualstudio.com/project/_apis/build/definitions?api-version=5.0-preview.6");
                  requestMessage.Content = new StringContent("{"process": {  "phases": [{"steps": [], "name": "Phase 1","refName": "Phase_1","condition": "succeeded()","target": { "executionOptions": { "type": 0 },"allowScriptsAuthAccessOption": false,  "type": 1  },  "jobAuthorizationScope": "projectCollection", "jobCancelTimeoutInMinutes": 1 }],"type": 1  }, "repository": { "properties": { "cleanOptions": "0","labelSources": "0","labelSourcesFormat": "$(build.buildNumber)", "reportBuildStatus": "true","gitLfsSupport": "false", "skipSyncSource": "false","checkoutNestedSubmodules": "false", "fetchDepth": "0"},"id": "4ba24767-e5a6-4987-80cc-ebaeca01fdbc","type": "TfsGit","name": "product1", "url": "https://marinaliu.visualstudio.com/Git2/_git/product1", "defaultBranch": "refs/heads/master",  "clean": "false","checkoutSubmodules": false },"processParameters": {}, "drafts": [],"queue": { "id": 324,  "name": "ownPC","pool": {"id": 23, "name": "ownPC"}}, "name": "definitionCreatedByRESTAPI", "type": "build","queueStatus": "enabled"}", Encoding.UTF8, "application/json");
                  
                  HttpResponseMessage response = client.SendAsync(requestMessage).Result;
                  response.EnsureSuccessStatusCode();
                  

                  通过参考博客Accessing TFS/VSTS 2017 programmatically 用于 C#程序.

                  By referring the blog Accessing TFS/VSTS 2017 programmatically for the C# program.

                  这篇关于如何通过 VSTS REST API 创建构建定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Force JsonConvert.SerializeXmlNode to serialize node value as an Integer or a Boolean(强制 JsonConvert.SerializeXmlNode 将节点值序列化为整数或布尔值)
                  Using JSON to Serialize/Deserialize TimeSpan(使用 JSON 序列化/反序列化 TimeSpan)
                  Could not determine JSON object type for type quot;Classquot;(无法确定类型“Class的 JSON 对象类型.)
                  How to deserialize a JSONP response (preferably with JsonTextReader and not a string)?(如何反序列化 JSONP 响应(最好使用 JsonTextReader 而不是字符串)?)
                  how to de-serialize JSON data in which Timestamp it-self contains fields?(如何反序列化时间戳本身包含字段的JSON数据?)
                  JSON.Net custom contract serialization and Collections(JSON.Net 自定义合约序列化和集合)

                        <tbody id='GZChY'></tbody>

                        <tfoot id='GZChY'></tfoot>

                        <small id='GZChY'></small><noframes id='GZChY'>

                          <bdo id='GZChY'></bdo><ul id='GZChY'></ul>
                        • <i id='GZChY'><tr id='GZChY'><dt id='GZChY'><q id='GZChY'><span id='GZChY'><b id='GZChY'><form id='GZChY'><ins id='GZChY'></ins><ul id='GZChY'></ul><sub id='GZChY'></sub></form><legend id='GZChY'></legend><bdo id='GZChY'><pre id='GZChY'><center id='GZChY'></center></pre></bdo></b><th id='GZChY'></th></span></q></dt></tr></i><div id='GZChY'><tfoot id='GZChY'></tfoot><dl id='GZChY'><fieldset id='GZChY'></fieldset></dl></div>

                            <legend id='GZChY'><style id='GZChY'><dir id='GZChY'><q id='GZChY'></q></dir></style></legend>