有没有办法在变量组中设置变量 [英] Is there a way to set variables in variable groups

查看:93
本文介绍了有没有办法在变量组中设置变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试共享来自不同管道的版本信息,以便以后使用它们在发布管道中创建发布配置.因此,基本上我需要在不同管道之间共享信息.

I'm trying to share version information from different pipelines to later use them to create a release config in a release pipeline. So basically I need to share information between different pipelines.

要创建某种独特的版本,我想始终使用git rev-parse HEAD的输出.

To create a somehow unique version I want to always use the output of git rev-parse HEAD.

我已经尝试使用变量组,但是我只能读取它们而不能设置它们.而且我不知道azure devops支持的另一种方式,我当然可以使用文件并发布它们.

I've already tried to use variable groups, but I was only able to read them and not to set them. And I'm not aware of another way which is supported by azure devops, I could of course use files and publish them.

我使用了文档提供的示例.

I used the example which was provided by the documentation.

#!/bin/bash
echo "##vso[task.setvariable variable=sauce]crushed tomatoes"

我希望在变量组中获得一个更改变量,以便稍后在发布管道中读取该变量. 感谢您的帮助.

I expect to get a change variable in the variable group in order to read that variable later on in a release pipeline. Any help is appreciated.

推荐答案

您不能使用记录命令task.setvariable更改变量组中的变量(记录命令只能在特定运行中更改).

You can not change a variable in a variable group with the logging command task.setvariable (the logging command can change only for a specific run).

更新变量组中变量的唯一方法是使用其他API :

The only way to update a variables in the variable group is with the Rest API:

PUT https://dev.azure/com/{organization}/{project}/_apis/distributestask/variablegroups/{groupId}?api-version=5.0-preview.1

请求正文:

{
   "variables": {
       "key1": {
          "value": "value1"
     }
  },
  "type": "Vsts",
  "name": "TestVarialeGroup",   
}

因此,您需要添加一个执行上述Rest API的任务,例如PowerShell:

So you need to add a task that excute the above Rest API, for example, PowerShell:

您需要允许脚本访问 OAuth令牌(选中代理作业选项中的复选框):

You need to allow scripts to access the OAuth token (check the checkbox in the agent job options):

并向构建用户(对变量组)授予Administrate权限:

And give Administrate permissions to the build user (to the variable group):

这篇关于有没有办法在变量组中设置变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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