Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger Azure Pipelines build via API

I made a working Azure Pipeline to build my codebase.

Looking for a way to trigger the Azure Pipelines build via API, ideally REST. If REST is not possible, perhaps I could try invoking the build via Azure Functions using a resource ID of sorts. I would like my own repository monitor to issue an API request that would trigger the build when my conditions are met. Another question - is it possible to set "pipeline variables" via API - e.g. I make an API call passing values to be used as my pipeline variables' values then triggers the build.

Thank you

like image 566
Moshe Shmukler Avatar asked Oct 09 '18 10:10

Moshe Shmukler


1 Answers

You can use the VSTS REST API or DevOps REST API to queue the build by giving the ID

VSTS POST:

https://account.visualstudio.com/project/_apis/build/builds?api-version=4.1

DevOps POST:

https://dev.azure.com/account/project/_apis/build/builds?api-version=6.1-preview.6

Body

{ 
        "definition": {
            "id": number
        } 
}

Refer to this solution

For your second question, Yes this is also possible, Just giving the parameters within the body

DevOps Body

{
    "parameters":  "{\"Parameter1\":  \"a value\"}",
    "definition":  {
                       "id":  2
                   }
}

Reference

Note: For these API calls make sure you use Basic Auth and pass a Personal Access Token as the value

like image 155
Jayendran Avatar answered Sep 27 '22 17:09

Jayendran