在C#中克隆VSTS构建定义 [英] Clone VSTS Build Definition in C#

查看:94
本文介绍了在C#中克隆VSTS构建定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用BuildHttpClient的.GetDefinitionAsync和.CreateDefinitionAsync来克隆VSTS构建定义。这可以正常工作,但我想在项目的根文件夹以外的其他文件夹中创建构建定义。我可以通过管理文件夹链接网站添加文件夹,但是如何以编程方式做到这一点?



我尝试了以下操作:

  buildDef = JsonConvert.DeserializeObject< BuildDefinition>(json); 
buildDef.BuildNumberFormat = buildNumFormat;
buildDef.Name = newBuildDefName;

Uri tfsURI = new Uri(CollectionReleaseURL);
buildDef.Url = tfsURI.ToString();
等待buildClient.CreateDefinitionAsync(buildDef,project);

集合发布所在的路径:
CollectionReleaseURL = @

解决方案

您要设置


I'm using BuildHttpClient's .GetDefinitionAsync and .CreateDefinitionAsync to clone a VSTS Build Definition. This works fine but I'd like to create the build defs in a different folder, other than the root folder of the project. I can add a folders via the "Manage Folders" link web but how can I do this programatically?

I've tried the following:

    buildDef = JsonConvert.DeserializeObject<BuildDefinition>(json);
    buildDef.BuildNumberFormat = buildNumFormat;
    buildDef.Name = newBuildDefName;

    Uri tfsURI = new Uri(CollectionReleaseURL);
    buildDef.Url = tfsURI.ToString();
    await buildClient.CreateDefinitionAsync(buildDef, project);

Where the Collection release is the path: CollectionReleaseURL = @"http://my.tfs.server8080/tfs/DefaultCollection/Project/Product/Release";

but when I run the program it just puts the new build def in the following folder: @"http://my.tfs.server8080/tfs/DefaultCollection/Project"

How can i clone the build def to the ../Product/Release folder?

UPDATE: I'm using the following to Clone the build def but it is NOT copying the Build Steps! Anyone know why that is?

private static async Task CloneBuildDefAsync(int buildDefId, string newBuildDefName, string buildNumFormat, string sourceControlPath, string URLpath)
{
    var buildClient = createClient();
    var buildDef = (await buildClient.GetDefinitionAsync(project, buildDefId)) as BuildDefinition;

    buildDef.Project = null;

    var json = JsonConvert.SerializeObject(buildDef);
    json = json.Replace(sourceControlMainline, sourceControlPath);
    buildDef = JsonConvert.DeserializeObject<BuildDefinition>(json);

    buildDef.BuildNumberFormat = buildNumFormat;
    buildDef.Name = newBuildDefName;
    buildDef.Path = URLpath;

    await buildClient.CreateDefinitionAsync(buildDef, project);
}

Seems to copy everything but the build step, everything else is cloned and updated perfectly:

解决方案

You want to set the Path property to the folder you want.

An example of the clone in 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'

Creates a build folder structure like this:

这篇关于在C#中克隆VSTS构建定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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