这是我们向产品团队报告的问题: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 }}