3

I want to trigger a specific Azure pipeline through REST API. I have checked this documentation . So the core message will be:

curl -x POST  $username:$personalaccesstoken https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=6.0-preview.1

Here, i cannot get find the $pipelineId anywhere in azure devops.

I have tried to Get Pipeline with REST APIs but the answer doesn't give me pipelineId. I have tried to create pipeline with az pipelines create to get the pipelineId in the result but it keeps asking me to az login although i do az login succesfully at first:

Before you can run Azure DevOps commands, you need to run the login command(az login if using AAD/MSA identity else az devops login if using PAT token) to setup credentials. Please see https://aka.ms/azure-devops-cli-auth for more information.

I have checked this post but it doesn't give the answer.

Honestly, if you have any idea me on how to find the pipelineId or any other method to trigger pipeline with REST API, you are more than welcome!

2 Answers 2

3

pipelineId is equal to definitionId

So please go to your pipeline and check url like this https://dev.azure.com/thecodemanual/DevOps%20Manual/_build?definitionId=177.

Or use this endpoint to get list of deifnitions:

https://dev.azure.com/{{organization}}/{{project}}/_apis/build/definitions?api-version=5.1
Sign up to request clarification or add additional context in comments.

Comments

1

If you want to start a new build, you may try to use this API: Builds - Queue

The definition id you can find in the URL of your build definition (as Krzysztof mentioned) or in the pipeline properties (in classic builds).

URL

enter image description here

Properties of the classic pipeline:

enter image description here

Then you can start a new build with powershell as example:

$user = ""
$token = "your_token"

$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))

$org = "org_name"
$teamProject = "team_project_name"
$defId = "build_definition_id"

$restApiRunBuild = "https://dev.azure.com/$org/$teamProject/_apis/build/builds?definitionId=$defId&api-version=6.1-preview.6"


function InvokePostReques ($PostUrl, $body)
{   
    return Invoke-RestMethod -Uri $PostUrl -Method Post -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}  -Body $body
}

$result = InvokePostReques $restApiRunBuild ""

$result

3 Comments

When I use this, I get "This request expects an object in the request body, but nothing was supplied"
Yeah, this answer doesn't work as it completely ignores the required body. The link in the question actually explains everything (including the body) except that pipelineId == definitionId.
@ChristianDavén Yes, it works only with Definition ID in the URL

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.