{
  "$type": "site.standard.document",
  "canonicalUrl": "https://johnnyreilly.com/posts/create-pipeline-with-azure-devops-api",
  "description": "Learn how to create an Azure Pipeline using the Azure DevOps REST API with a personal access token and JSON file, as detailed in this post.",
  "path": "/posts/create-pipeline-with-azure-devops-api",
  "publishedAt": "2021-05-08T00:00:00.000Z",
  "site": "at://did:plc:yy3apqjlms24kso7ahn7lbmb/site.standard.publication/3mova7c4nho2b",
  "tags": [
    "azure pipelines",
    "azure devops",
    "typescript"
  ],
  "textContent": "Creating an Azure Pipeline using the Azure DevOps REST API is possible, but badly documented. This post goes through how to do this; both using curl and using TypeScript.\n\nIf you're curious as to how to list pipelines, then check out my post on listing pipelines with the Azure DevOps API.\n\n\n\ncurling a pipeline\n\nThe documentation for creating an Azure Pipeline using the Azure DevOps API is somewhat lacking. It doesn't mention key parameters like repository and path which are necessary to create a correctly configured pipeline. However, whilst it isn't documented officially, it can be done. You just need the recipe.\n\nHere's a curl to make you a pipeline:\n\nLooking at the above there's two things you need:\n\n1. A personal access token. You can make one of those here: https://dev.azure.com/organisation-name/_usersSettings/tokens (where organisation-name is the name of your organisation)\n2. A makepipeline.json file, which contains the details of the pipeline you want to create:\n\nLet's talk through the significant properties above:\n\n- 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.\n- name - your pipeline needs a name\n- 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.\n- repository.id - this is the guid that represents the repo you're creating the pipeline for. You can find this out by going to your equivalent https://dev.azure.com/organisation-name/project-name/_settings/repositories (substituting in appropriate values) and looking up your repository there.\n- repository.name - the name of your repo\n\nWhen you execute your curl you should be returned some JSON along these lines:\n\nAnd inside Azure DevOps you'll now have a shiny new pipeline:\n\nWhat if I want to use TypeScript?\n\nIf you'd like to do the same in TypeScript, you can use the azure-devops-node-api package. Just like the official documentaion, the package is short of the necessary parameters to create a pipeline such as repository and path. But by combining a little fetch with the azure-devops-node-api you can get the job done.\n\nHere's a TypeScript example:\n\nThe above code:\n\n1. Gets the repository id using the azure-devops-node-api\n2. Creates a pipeline using fetch and the Azure DevOps REST API, with the types we've created to help us understand the shape of the data we're working with",
  "title": "Create a Pipeline with the Azure DevOps API"
}