[英]Pass a Variable group name using REST API Azure devops
Is there any way to pass a variable group name to a release pipeline using REST API without editing the release definition.有没有办法在不编辑发布定义的情况下使用 REST API 将变量组名称传递给发布管道。
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.但问题是“ Put ”请求更新原始定义。 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.恐怕没有这种方法可以在不编辑发布定义的情况下传递
Variablegroup
。
To pass the Variablegroup
name to the release definition, we have to use the Put request to update the definition.要将
Variablegroup
名称传递给发布定义,我们必须使用Put请求来更新定义。 Since there is no option/REST API we could use to update the definition when we run the release pipeline.由于没有选项/REST API,我们可以在运行发布管道时使用它来更新定义。
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.如果您不想修改原始定义,您可以在原始定义中获取
Variablegroup
名称,然后使用上面的 REST API 添加/更新Variablegroup
名称。 At the end of the release pipeline, we could invoke again above REST API to restore the Variablegroup
name in the original definition.在发布管道的末尾,我们可以再次调用上面的 REST API 来恢复原始定义中的
Variablegroup
名称。
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.此外,如果您添加的变量组中的变量不多,您可以在发布管道中使用Logging 命令覆盖变量,这不会改变原始定义。
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.希望这可以帮助。
You are using the same $defurl
with a get, then a post.您使用相同的
$defurl
与 get 和 post。 The post is trying to perform an update on the definition api doc src so this code will always update the release definition.该帖子试图对定义api doc src执行更新,因此此代码将始终更新发布定义。
I think the endpoint you are looking for is release -> Create which will start a new deployment.我认为您正在寻找的端点是release -> Create这将开始一个新的部署。 I have not modified Variable Groups using this endpoint, but have overrode specific variables and will try to add some code to my answer if a better answer does not pop up.
我没有使用这个端点修改变量组,但已经覆盖了特定的变量,如果没有弹出更好的答案,我会尝试在我的答案中添加一些代码。
I found that using fiddler to inspect the REST calls that the web gui sends helped me figure out exactly how my json body needed to look like.我发现使用 fiddler 检查 web gui 发送的 REST 调用帮助我弄清楚我的 json body 需要看起来像什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.