使用Azure Build API将参数传递给Azure yaml管道时遇到问题

时间:2020-07-13 17:38:12

标签: azure-devops azure-pipelines-yaml

我尝试使用以下管道中的参数::

  • 名称:var1 displayName:var1 类型:字符串 默认值:variable2 值:
    • 变量2
    • variable3
    • 变量4

现在,当我尝试击中邮递员并在下面按正文传递参数

对-> https://dev.azure.com/ / / _ apis / build / builds?api-version = 5.0的调用 正文->

{ “ definition”:{“ id”:1234}, “ var1”:“ variable1” }


当我在管道中获取参数值时仍然如此。我获取默认值,而不是使用api传递的值。

echo“传递的变量为$ {{parameters.var1}}” 输出->传递的变量为variable2

谢谢 沙拉德

1 个答案:

答案 0 :(得分:0)

这是我们已报告给产品团队的问题:https://developercommunity.visualstudio.com/content/problem/1000544/parameters-to-api-rest-build-queue-method.html

目前,作为一种解决方法,我们可以使用下面未公开的REST API(由开发工具跟踪)通过传递参数来触发YAML管道。

POST https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineID}/runs?api-version=5.1-preview.1

Content-Type: application/json
Accept: application/json

Request body:

{
 "stagesToSkip":[],
 "resources":{
   "repositories":{
     "self":{
       "refName":"refs/heads/master"
       }
    }
 },
 "templateParameters":{
   "image":"ubuntu-16.04",
   "var1":"variable1"
   },
  "variables":{}
}

Yaml文件供您参考:

parameters:
- name: image
  displayName: Pool Image
  type: string
  default: ubuntu-latest
  values:
  - windows-latest
  - vs2017-win2016
  - ubuntu-latest
  - ubuntu-16.04
  - macOS-latest
  - macOS-10.14

- name: var1 
  displayName: var1 
  type: string 
  default: variable2 
  values:
  - variable1 
  - variable2
  - variable3
  - variable4


trigger: none


jobs:
- job: build
  displayName: build
  pool: 
    vmImage: ${{ parameters.image }}
  steps:
  - script: echo building $(Build.BuildNumber) with ${{ parameters.image }}
  - script: echo building $(Build.BuildNumber) with ${{ parameters.var1 }}