簡體   English   中英

使用Azure Devops API創建生成定義

[英]Create Build Definition using Azure Devops API

我們正在嘗試通過使用Azure Devops Rest API復制另一個構建定義信息來創建構建定義,但是出現以下錯誤:

HttpError BadRequest-值不能為null。 參數名稱:definition.Repository.Mappings.Mapping.ServerPath。

這是我們要遵循的步驟

  1. 使用API​​獲取構建信息-此步驟工作正常
  2. 修改構建定義的名稱
  3. 通過傳遞上述構建定義請求主體來創建新的構建定義

樣例代碼

var buildDefinitionGet = client.GetBuildDefinitionsAsync("XXX.DevOps", "15");

var newBuildDefinition = buildDefinitionGet;
newBuildDefinition.name = "MVC2017-1";

var buildDefinition = await client               
   .CreateBuildDefinitionsAsync("XXX.DevOps", newBuildDefinition)
   .ConfigureAwait(false);

這是請求主體結構:

public class BuildDefinitionRequestBody
{
    public Process process { get; set; }
    public Repository repository { get; set; }
    public ProcessParameters processParameters { get; set; }
    public List<object> drafts { get; set; }
    public Queue queue { get; set; }
    public string name { get; set; }
    public string type { get; set; }
    public string queueStatus { get; set; }
}

我們正在使用TFVC作為源代碼控制。

我們錯過了什么嗎?

在這些情況下,有兩種類型錯誤,

definition.Repository.Mappings.Mapping.ServerPath ”和“ definition.Repository.Mappings.Mapping.LocalPath”。

路徑中的以下情況將導致上述錯誤。

definition.Repository.Mappings.Mapping.LocalPath


  1. 不允許使用unc路徑
  2. 本地映射不允許是絕對路徑或導航到s目錄之外
  3. 兩個映射不應具有相同的本地路徑
  4. 本地路徑號為0或映射號為0

definition.Repository.Mappings.Mapping.ServerPath


  1. 不允許使用無效字符
  2. 服務器路徑或類型不允許使用空字段
  3. 兩個映射不應具有相同的服務器路徑

由於屏幕快照並未顯示完整的本地路徑和服務器路徑,因此請根據您自己的上述規則檢查路徑。 我建議您從頁面頂部的相應項目的“代碼”->“文件”中復制“服務器路徑”值,以確保服務器路徑正確。 對於本地路徑,建議您一一刪除,以確保引起此問題的是哪一個。

用於克隆構建的Powershell等效代碼。

 $uri = 'https://dev.azure.com/{organization}/{project}/_apis/build/definitions/{definitionId}' $result = Invoke-RestMethod -Method Get -Uri $uri -UseDefaultCredentials $result.path = '\\NewFolder\\Location' $result.name = "Testing" $body = $result | ConvertTo-Json -Depth 7 Invoke-RestMethod -Method POST -uri 'https://dev.azure.com/{organization}/{project}/_apis/build/definitions?api-version=4.0' -UseDefaultCredentials -Body $body -ContentType 'application/json' 

希望能幫助到你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM