Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure devops pass build parameters through Rest API

I'm trying to pass a parameters through the build rest API using jira, but it doesn't override the parameter.

Pipeline:

parameters:
- name: "Testplan"
  type: string
  default: "NoPlanDefined"

stage: Test
  jobs:
  - job: Testing_And_Transfer
    - task: PowerShell@2
        displayName: "Testing API Call"
        inputs:
          targetType: 'filepath'
          filePath: './script/Jira.ps1'
          arguments: 
            -Jira_id ${{ parameters.Testplan }}

Jira.ps1 content:

Param(
    [string]$Jira_id = "no ID"
)
#-----------------------Jira API--------------------------
echo 'This is a test \n ID: '
echo $Jira_id

My rest command is setup like so:

URL: https://dev.azure.com/{My corp}/MyHello/_apis/build/builds?api-version=6.0

Body:

{    
    "definition":  { 
        "id": 1 
        },
    "parameters": "{ \"Testplan\":\"Postman\" }"
}
  • When using the trigger, the ps1 return NoPlanDefined as expected.
  • When using a manual trigger and changing the parameter, the parameter get changed as expected.
  • When trying to change the parameter through the Rest api, Testplan is empty instead of Postman.

I'm I doing something wrong with the REST API?

like image 334
Alexandre S.M Avatar asked Aug 27 '26 02:08

Alexandre S.M


1 Answers

That's because those are not parameters, despite the name used in the REST call. They are run-time variables, which behave differently and are available at a different scope than parameters.

There is a different API that allows you to specify templateParameters: https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/run-pipeline?view=azure-devops-rest-6.1

like image 91
Daniel Mann Avatar answered Aug 31 '26 11:08

Daniel Mann



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!