4

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?

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

At least at the time of this writing, the Build API in the OP will work also. But it's very important to keep in mind that templateParameters is an object not a string. Hence in the payload the parameters attribute becomes "parameters": { Testplan: "Postman" }
0

If you are familiar with PowerShell you can use the AzurePipelinesPS module and the command below to pass parameters to pipelines when invoking them.

$id = '2' # your pipeline id
$templateParameters = @{
    Testplan = 'myTestPlan' # your parameter and value
}
Invoke-APPipeline -Instance https://dev.azure.com -Collection 'yourCollectionName' -Project 'yourProjectName' -ApiVersion '6.0-preview.1' -PipelineId $id -TemplateParameters $templateParameters

The module supports "sessions" to limit the number of required parameters. See the module's github page on how to create a session.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.