Skip to main content

Create a Pipeline with the Azure DevOps API

· 2 min read

Creating an Azure Pipeline using the Azure DevOps REST API is possible, but badly documented. This post goes through how to do this.

curling a pipeline#

The documentation for creating an Azure Pipeline using the Azure DevOps API is somewhat lacking. However it isn't actually too hard, you just need the recipe.

Here's a curl to make you a pipeline:

curl  --user '':'PERSONAL_ACCESS_TOKEN' --header "Content-Type: application/json" --header "Accept:application/json" -d @makepipeline.json

Looking at the above there's two things you need:

  1. A personal access token. You can make one of those here: (where organisation-name is the name of your organisation)
  2. A makepipeline.json file, which contains the details of the pipeline you want to create:
{    "folder": null,    "name": "pipeline-made-by-api",    "configuration": {        "type": "yaml",        "path": "/azure-pipelines.yml",        "repository": {            "id": "guid-of-repo-id",            "name": "my-repo",            "type": "azureReposGit"        }    }}

Let's talk through the significant properties above:

  • folder - can be null if you'd like the pipeline to be created in the root of Pipelines; otherwise provide the folder name. Incidentally a null will be translated into a value of \\ which appears to be the magic value which represents the root.
  • name - your pipeline needs a name
  • path - this is the path to the yaml pipelines file in the repo. Note we're creating the pipeline itself here; what's actually in the pipeline sits in that file.
  • - this is the guid that represents the repo you're creating the pipeline for. You can find this out by going to your equivalent (substituting in appropriate values) and looking up your repository there.
  • - the name of your repo

When you execute your curl you should be returned some JSON along these lines:

{    "_links": {        "self": {            "href": ""        },        "web": {            "href": ""        }    },    "configuration": {        "path": "/azure-pipelines.yml",        "repository": {            "id": "9a72560d-1622-4016-93dd-32ac85b96d03",            "type": "azureReposGit"        },        "type": "yaml"    },    "url": "",    "id": 975,    "revision": 1,    "name": "pipeline-made-by-api",    "folder": "\\"}

And inside Azure DevOps you'll now have a shiny new pipeline:

The new pipeline