使用REST API Azure devop传递变量组名称 [英] Pass a Variable group name using REST API Azure devops

本文介绍了使用REST API Azure devop传递变量组名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用REST API将变量组名传递到发布管道,而无需编辑发布定义.

我可以使用以下方法

  $ defurl ="https://vsrm.dev.azure.com/org/proj/_apis/release/definitions/13?api-version=5.1"$ def = Invoke-RestMethod -Uri $ defurl -Method Get -Headers $ header$ def.variableGroups ="VariableGroupName"$ json = @($ def)|ConvertTo-Json-深度99$ udef = Invoke-RestMethod -Uri $ defurl -Method Put -Body $ json -ContentType"application/json" -Headers $ header 

但是问题是"放置"请求更新原始定义.有什么方法可以传递变量组而无需编辑发行版定义.即时编辑发布"定义以传递变量组是否是一种好习惯?

解决方案

有什么方法可以传递变量组而无需编辑发行版定义

恐怕没有这样的方法来传递 Variablegroup 而无需编辑发布定义.

要将 Variablegroup 名称传递到版本定义,我们必须使用 Put 请求来更新定义.由于没有选项/REST API,因此我们在运行发布管道时可以用来更新定义.

如果您不想修改原始定义,则可以在原始定义中获取 Variablegroup 名称,然后使用上述REST API添加/更新 Variablegroup 名称.在发布流程的最后,我们可以再次在REST API之上调用以在原始定义中恢复 Variablegroup 名称.

此外,如果您添加的变量组中的变量不多,则可以使用

希望这会有所帮助.

Is there any way to pass a variable group name to a release pipeline using REST API without editing the release definition.

I am able to do it using the following

   $defurl = "https://vsrm.dev.azure.com/org/proj/_apis/release/definitions/13?api-version=5.1" 
   $def = Invoke-RestMethod -Uri $defurl -Method Get -Headers $header
   $def.variableGroups="VariableGroupName"
   $json = @($def) | ConvertTo-Json -Depth 99 
   $udef = Invoke-RestMethod  -Uri $defurl  -Method Put -Body $json -ContentType "application/json" -Headers $header

But the problem is "Put" request updating the Original definition. Is there any way to pass the Variablegroup without editing the release definition. Is this a good practice to edit the Release defnition on the fly to pass the variable group.

解决方案

Is there any way to pass the Variablegroup without editing the release definition

I am afraid there is no such way to pass the Variablegroup without editing the release definition.

To pass the Variablegroup name to the release definition, we have to use the Put request to update the definition. Since there is no option/REST API we could use to update the definition when we run the release pipeline.

If you do not want to modify the original definition, you could get the Variablegroup name in the original definition, then use above REST API to add/update the Variablegroup name. At the end of the release pipeline, we could invoke again above REST API to restore the Variablegroup name in the original definition.

Besides, if there are not many variables in the variable group you added, you could use the the Logging Command during the release pipeline to overwrite the variables, which would not change the original definition.

Write-Host "##vso[task.setvariable variable=testvar;]testvalue"

Update:

How to use this logging command outside the release pipeline to modify the Variable group???

The answer is NO. That because we could not update the the variable group when we create the release pipeline, it only shows the release variable:

Hope this helps.

这篇关于使用REST API Azure devop传递变量组名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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