有没有办法在变量组中设置变量

时间:2019-06-12 08:49:51

标签: azure-devops continuous-integration azure-pipelines

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

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

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

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

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

我希望在变量组中获得一个更改变量,以便稍后在发布管道中读取该变量。 任何帮助表示赞赏。

2 个答案:

答案 0 :(得分:2)

可以通过Azure devops CLI完成。

创建powershell任务:

echo $env:AZURE_DEVOPS_EXT_PAT | az devops login
az devops configure -d organization=https://dev.azure.com/<your_organisation>/ project=<your_project>

az pipelines variable-group variable update --id <id_here> --name <name_here> --value <value_here>

并在任务中像这样创建变量 enter image description here

答案 1 :(得分:0)

您无法使用日志记录命令task.setvariable来更改变量中的变量。

更新变量组中变量的唯一方法是使用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:

enter image description here

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

enter image description here

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

enter image description here

相关问题