[英]Create Build Definition using Azure Devops API
We are trying to create build definition by copy another build definition information using Azure Devops Rest API however getting the below error: 我们正在尝试通过使用Azure Devops Rest API复制另一个构建定义信息来创建构建定义,但是出现以下错误:
HttpError BadRequest - Value cannot be null. HttpError BadRequest-值不能为null。 Parameter name: definition.Repository.Mappings.Mapping.ServerPath. 参数名称:definition.Repository.Mappings.Mapping.ServerPath。
Here are the steps we are following 这是我们要遵循的步骤
Sample code 样例代码
var buildDefinitionGet = client.GetBuildDefinitionsAsync("XXX.DevOps", "15");
var newBuildDefinition = buildDefinitionGet;
newBuildDefinition.name = "MVC2017-1";
var buildDefinition = await client
.CreateBuildDefinitionsAsync("XXX.DevOps", newBuildDefinition)
.ConfigureAwait(false);
Here is the request body structure: 这是请求主体结构:
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; }
}
We are using TFVC as source control. 我们正在使用TFVC作为源代码控制。
Are we missing anything? 我们错过了什么吗?
In these scenarios, there are two type error, 在这些情况下,有两种类型错误,
“ definition.Repository.Mappings.Mapping.ServerPath ” and “definition.Repository.Mappings.Mapping.LocalPath”. “ definition.Repository.Mappings.Mapping.ServerPath ”和“ definition.Repository.Mappings.Mapping.LocalPath”。
Following situation in your path will cause above error. 路径中的以下情况将导致上述错误。
definition.Repository.Mappings.Mapping.LocalPath : definition.Repository.Mappings.Mapping.LocalPath :
definition.Repository.Mappings.Mapping.ServerPath : definition.Repository.Mappings.Mapping.ServerPath :
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. 用于克隆构建的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'
Hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.