BuildHTTPClient无法获得构建定义步骤? [英] BuildHTTPClient not able to get Build Definition Steps?

查看:172
本文介绍了BuildHTTPClient无法获得构建定义步骤?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用BuildHTTPClient来以编程方式创建构建定义的副本,更新内存中的变量,然后将更新后的对象另存为新定义.

We are using the BuildHTTPClient to programmatically create a copy of a build definition, update the variables in memory and then save the updated object as a new definition.

我正在使用

I'm using Microsoft.TeamFoundation.Build2.WebApi.BuildHTTPClient 16.141. The TFS version is 17 update 3 (rest api 3.x)

这是与 https://serverfault.com类似的问题/questions/799607/tfs-buildhttpclient-updatedefinition-c-example ,但我尝试使用BuildHttpClient库,而不是直接进入RestAPI.

This is a similar question to https://serverfault.com/questions/799607/tfs-buildhttpclient-updatedefinition-c-example but I'm trying to stay within using the BuildHttpClient libraries and not go directly to the RestAPIs.

问题在于,即使我们在构建定义中使用了步骤"列表,其他属性也始终为空.

The problem is the Steps list is always null along with other properties even though we have them in the build definition.

更新在下面作为答案发布

查看下面的@Daniel Frosts尝试之后,我们开始考虑使用NuGet软件包的旧版本.令人惊讶的是,受支持的版本15.131.1不支持此功能,但是我们发现版本="15.112.0-preview"可以. 回滚我们所有的Dll以匹配该版本后,在保存该构建的新副本时将克隆这些步骤.

After looking at @Daniel Frosts attempt below we started looking at using older versions of the NuGet package. Surprisingly the supported version 15.131.1 does not support this but we have found out that the version="15.112.0-preview" does. After rolling back all of our Dlls to match that version the steps were cloned when saving the new copy of the build.

当您使用此程序包时,我们使用的所有代码示例均有效.我们无法使Daniel的示例正常工作,但Dll的版本才是问题所在.

All of the code examples we used work when you are using this package. We were unable to get Daniel's example working but the version of the Dll was the issue.

我们需要创建GitHub问题并将其报告给MS

We need to create a GitHub issue and report it to MS

首次尝试-GetDefinitionAsync:

VssConnection connection = new VssConnection(DefinitionTypesDTO.serverUrl, new VssCredentials());
BuildHttpClient bdClient = connection.GetClient<BuildHttpClient>();

Task <BuildDefinition> resultDef = bdClient.GetDefinitionAsync(DefinitionTypesDTO.teamProjectName, buildID);
resultDef.Wait();
BuildDefinition updatedDefinition = UpdateBuildDefinitionValues(resultDef.Result, dr, defName);
updatedTask = bdClient.CreateDefinitionAsync(updatedDefinition, DefinitionTypesDTO.teamProjectName);

更新对变量起作用,我们可以将更新的定义保存回TFS,但是新创建的构建定义中没有任何任务.当我们查看从GetDefinitionAsync返回的对象时,我们看到步骤"列表为空.看起来GetDefinitionAsync只是没有获得完整的对象.

The update works on the variables and we can save the updated definition back to TFS but there are not any tasks in the newly created build definition. When we look at the object that is returned from GetDefinitionAsync we see that the Steps list is empty. It looks like GetDefinitionAsync just doesn't get the full object.

第二次尝试-具体修订:

int rev = 9;
Task <BuildDefinition> resultDef = bdClient.GetDefinitionAsync(DefinitionTypesDTO.teamProjectName, buildID, revision: rev);
resultDef.Wait();
BuildDefinition updatedDefinition = UpdateBuildDefinitionValues(resultDef.Result, dr, defName);

基于SteveSims的帖子,我们认为我们没有得到正确的修订.因此,我们在请求中添加了修订.使用正确的修订版,我会看到相同的问题.与SteveSims帖子类似,我可以在浏览器中打开DefinitionURL,我看到任务在浏览器的JSON中,但是BuildDefinition对象没有填充它们.

Based on SteveSims post we were thinking we are not getting the correct revision. So we added revision to the request. I see the same issue with the correct revision. Similarly to SteveSims post I can open the DefinitionURL in a browser and I see that the tasks are in the JSON in the browser but the BuildDefinition object is not populated with them.

三次尝试-GetFullDefinition:

所以我当时想尝试getFullDefinition,也许那是"Full"的意思,当然我不知道这些库上没有任何文档.

So then I thought to try getFullDefinition, maybe that's that "Full" means of course with out any documentation on these libraries I have no idea.

var task2 = bdClient.GetFullDefinitionsAsync(DefinitionTypesDTO.teamProjectName, "MyBuildDefName","$/","TfsVersionControl");
task2.Wait();

仍然没有运气,即使我们在构建定义中包含步骤,步骤"列表也始终为空.

Still no luck, the Steps list is always null even though we have steps in the build definition.

第四次尝试-另存为模板

var task2 = bdClient.GetTemplateAsync DefinitionTypesDTO.teamProjectName, "1_Batch_Dev");
task2.Wait();

我尝试将构建定义保存为模板.因此,在Web UI中,我选择了另存为模板",仍然没有任何步骤.

I tried saving the Build Definition off as a template. So in the Web UI I chose "Save as Template", still no steps.

第五次尝试:使用SteveSims帖子中提到的URL:

最后我说好,我将尝试使用SteveSims解决方案,使用webclient从URL获取对象.

Finally i said ok, i'll try the solution SteveSims used, using the webclient to get the object from the URL.

var client = new WebClient();
client.UseDefaultCredentials = true;
var json = client.DownloadString(LastDefinitionUrl);

//Convert the JSON to an actual builddefinition
BuildDefinition result = JsonConvert.DeserializeObject<BuildDefinition>(json);

这也不起作用.构建定义步骤为空.即使在查看Json对象(var json)时,我也看到了这些步骤.但是对象未加载它们.

This also didn't work. The build definition steps are null. Even when looking at the Json object (var json) i see the steps. But the object is not loaded with them.

我看过这篇帖子,似乎在基本定义中添加了步骤,我已经尝试过了,但是老实说,我在理解他如何通过NuGet引用BuildDefinition对象时修改了该问题.

I've seen this post which seems to add the Steps to the base definition, i've tried this but honestly I'm having an issue understanding how he has modified the BuildDefinition Object when referencing that via NuGet?

https://dennisdel.com/blog/getting-build-steps-with-visual-studio-team-services-.net-api/

推荐答案

在查看下面的@Daniel Frosts尝试之后,我们开始研究使用NuGet包的旧版本.令人惊讶的是,受支持的版本15.131.1不支持此功能,但我们发现版本="15.112.0-preview"可以.
回滚我们所有的Dll以匹配该版本后,在保存该构建的新副本时将克隆这些步骤.

After looking at @Daniel Frosts attempt below we started looking at using older versions of the NuGet package. Surprisingly the supported version 15.131.1 does not support this but we have found out that the version="15.112.0-preview" does.
After rolling back all of our Dlls to match that version the steps were cloned when saving the new copy of the build.

使用此程序包时,以上所有代码示例均适用.我们无法使Daniel的示例正常工作,但是我们没有努力,因为我们拥有有效的代码.

All of the code examples above work when you are using this package. We were unable to get Daniel's example working but we didn't try hard as we had working code.

我们需要为此创建一个GitHub问题.

We need to create a GitHub issue for this.

这篇关于BuildHTTPClient无法获得构建定义步骤?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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