0
votes

I tried using parameters in pipeline per below ::

  • name: var1 displayName: var1 type: string default: variable2 values:
    • variable2
    • variable3
    • variable4

now when i am trying to hit by postman and passing parameter in body per below

post call to --> https://dev.azure.com/<org_name>/<prj_name>/_apis/build/builds?api-version=5.0 body -->

{ "definition": {"id": 1234}, "var1":"variable1" }


still when i get the parameter value in pipeline.. i get the default value and not the one i passed using api.

echo "Passed variable is ${{ parameters.var1 }}" output --> Passed variable is variable2

Thanks Sharad

1

1 Answers

0
votes

This is an issue we have reported to the product team : https://developercommunity.visualstudio.com/content/problem/1000544/parameters-to-api-rest-build-queue-method.html

Currently as a workaround we can use below undocumented REST API (tracked by develop tool) to trigger the YAML pipeline by passing the parameters.

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 file for your reference:

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 }}