9

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

Jayendran
  • 8,189
  • 5
  • 47
  • 93
Moshe Shmukler
  • 1,204
  • 2
  • 20
  • 38

1 Answers1

24

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

John
  • 28,415
  • 18
  • 87
  • 126
Jayendran
  • 8,189
  • 5
  • 47
  • 93
  • Hello Jayendran . I am trying the same for creating release pipeline . But I get page not found . Can you please help . https://stackoverflow.com/questions/53225115/release-pipeline-api-is-not-working-in-azure-devops – Balakumar Ezhilmaran Nov 09 '18 at 12:01
  • @bkr glad you got the answer by yourself – Jayendran Nov 09 '18 at 14:40
  • 4
    *Important*: In the newest version of the API `parameters` is a string and no JSON object anymore. But the string should contain JSON. So you have to escape a JSON object, like so: `"parameters": "{ \"param1\": \"value1\" }"` – D.R. Jul 04 '19 at 09:29
  • I am struggling with either methods: https://stackoverflow.com/questions/63654387/azure-rest-api-for-building-pipelines Please help. – Yahya Uddin Aug 30 '20 at 05:53