简体   繁体   English

使用 REST API Azure devops 传递变量组名称

[英]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.

相关问题 Azure DevOps 使用 REST API 调用 GetItem - Azure DevOps calling GetItem using REST API 如何使用 powershell(Azure devops REST API)获取用户提交更改的 Azure devops git repo 文件夹名称 - How to get Azure devops git repo folder name where user committed changes using powershell (Azure devops REST API) 如何使用 Rest API 将变量组链接到 azure 管道? - How to link variable group to azure pipeline using Rest API? 将 Artifact 传递给 Azure devops Rest api POST 方法 - Pass Artifact to Azure devops Rest api POST method 如何使用 Azure DevOps REST API 设置发布定义工件 - How to set Release Definition artifacts using Azure DevOps REST API 使用 Powershell 的 Azure Devops 审计 rest api 延续令牌 - Azure Devops audit rest api continuation token using powershell Azure devops rest api 结果使用 powershell 脚本循环 - Azure devops rest api result looping using powershell script 在PowerShell中使用Azure DevOps REST API更新内部版本定义 - Update build definition using Azure DevOps REST API in PowerShell 使用 Rest API 在 Azure Devops 中创建工作项时出错 - Error while creating Work Item in Azure Devops using Rest API 如何使用 Devops REST API 搜索带有 Powershell 的 Azure Devops 代码存储库并输出到 CSV - How to search Azure Devops Code Repos w/ Powershell using Devops REST API and output to CSV
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM