[英]Create Build Definition using Azure Devops API
我們正在嘗試通過使用Azure Devops Rest API復制另一個構建定義信息來創建構建定義,但是出現以下錯誤:
HttpError BadRequest-值不能為null。 參數名稱:definition.Repository.Mappings.Mapping.ServerPath。
這是我們要遵循的步驟
樣例代碼
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 :
definition.Repository.Mappings.Mapping.ServerPath :
由於屏幕快照並未顯示完整的本地路徑和服務器路徑,因此請根據您自己的上述規則檢查路徑。 我建議您從頁面頂部的相應項目的“代碼”->“文件”中復制“服務器路徑”值,以確保服務器路徑正確。 對於本地路徑,建議您一一刪除,以確保引起此問題的是哪一個。
用於克隆構建的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.