Create Build Definition using Azure Devops API

会有一股神秘感。 提交于 2019-12-06 22:20:28

In these scenarios, there are two type error,

definition.Repository.Mappings.Mapping.ServerPath” and “definition.Repository.Mappings.Mapping.LocalPath”.

Following situation in your path will cause above error.

definition.Repository.Mappings.Mapping.LocalPath:


  1. unc paths are not allowed
  2. local mappings are not allowed to be absolute paths or to navigate out of the s dir
  3. two mappings should not have the same local path
  4. Local Path number is 0 or mapping number is 0

definition.Repository.Mappings.Mapping.ServerPath:


  1. no invalid characters allowed
  2. no empty fields allowed for server path or type
  3. two mappings should not have the same server path

Since the screenshots doesn’t show the whole local path and the server path , please check the paths based on above rules on your side. And I suggest you copy the Server Path value from the corresponding project’s Code -> Files, on the top of the page, which could make sure the server paths are correct. For the local paths, I suggest you remove the one by one to make sure which one caused this issue.

Powershell equivalent code for cloning build.

$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'

Hope it helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!