使用Azure Devops API创建生成定义 [英] Create Build Definition using Azure Devops API

查看:39
本文介绍了使用Azure Devops API创建生成定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试通过使用Azure Devops Rest API复制另一个构建定义信息来创建构建定义,但是出现以下错误:

We are trying to create build definition by copy another build definition information using Azure Devops Rest API however getting the below error:

HttpError BadRequest-值不能为null.参数名称: 定义.Repository.Mappings.Mapping.ServerPath.

HttpError BadRequest - Value cannot be null. Parameter name: 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作为源代码控制.

We are using TFVC as source control.

我们有什么遗漏吗?

推荐答案

在这些情况下,存在两种类型的错误

In these scenarios, there are two type error,

" definition.Repository.Mappings.Mapping.ServerPath "和"definition.Repository.Mappings.Mapping.LocalPath".

"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路径
  2. 不允许将本地映射作为绝对路径或从sdir导航出去
  3. 两个映射不应具有相同的本地路径
  4. 本地路径号为0或映射号为0

definition.Repository.Mappings.Mapping.ServerPath :

  1. 不允许使用无效字符
  2. 服务器路径或类型不允许有空字段
  3. 两个映射不应具有相同的服务器路径

由于屏幕截图并未显示完整的本地路径和服务器路径,因此请根据上述规则检查路径.而且我建议您从页面顶部相应项目的代码"->文件"中复制服务器路径"值,以确保服务器路径正确.对于本地路径,建议您一一删除,以确保引起此问题的是哪一个.

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等效代码.

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'

希望有帮助.

这篇关于使用Azure Devops API创建生成定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆