TFS REST Api更新构建定义或在构建C#排队时传递变量 [英] TFS REST Api Update Build Definition Or Pass Variable While Queuing the Build C#
问题描述
在尝试使用C#编写的控制台应用程序更新TFS中现有的构建定义时遇到了一个问题.我正在成功排队构建,但是如我所见,我传入参数的参数未应用到构建中.我尝试在触发它之前更新定义,但是我也收到了错误的请求.哪种方法更好,如果有人这样做,我会寻求帮助.我唯一需要的是传递一些参数.我也不想传递字符串.谢谢:)
I've ran into a problem while trying to update my existing build definition in TFS by a console application written on C#. I am queuing a build successfully but the arguments i pass in parameters are not applied in the build as I can see. I tried to update the definition before I trigger it but i receive bad requests on it also.Which approach is better and if someone did it before I will ask for assistance with it. The only thing i need is to pass some parameters. I prefer not to pass strings as well too. Thanks :)
我正在遵循TFS REST Api文档-> https://www.visualstudio.com/zh-CN/integrate/api/build/definition-templates
I am following the TFS REST Api documentation -> https://www.visualstudio.com/en-us/integrate/api/build/definition-templates
推荐答案
您可以尝试一下.动态定制您的构建过程
$url = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$env:SYSTEM_TEAMPROJECTID/_apis/build/definitions/$($env:SYSTEM_DEFINITIONID)?api-version=2.0"
$definition = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"} -Method Get -ContentType application/json
Write-Host "Befor json = $($definition | ConvertTo-Json -Depth 100)"
$definition.build[1].enabled = "True"
$definition.build[1].inputs.msbuildArgs = "\OutPath bla-bla-bla"
$Updatedefinition = Invoke-RestMethod -uri $url -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"} -Method PUT -Body (Convertto-Json $Updatedefinition -Depth 100) -ContentType "application/json"
Write-Host "After json = $($Updatedefinition | ConvertTo-Json -Depth 100)"
这篇关于TFS REST Api更新构建定义或在构建C#排队时传递变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!