Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

This is a basic demonstration of what is needed to run a Azure DevOps CI build by calling their REST API. We are using Figmagic for this demo, to demonstrate running it in CI.

Notifications You must be signed in to change notification settings

mikaelvesavuori/azure-devops-ci-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Azure DevOps CI demo through REST API

This is a basic demonstration of what is needed to run a Azure DevOps CI build by calling their REST API.

We are using Figmagic for this demo, to demonstrate running it in CI. Even if you don't care for that specific tool, you'll get the gist how to automate stuff in CI here.

Instructions

I am assuming that you will set up a repo in Azure DevOps with the provided pipeline. If you have not, do so as the first step.

Set variables for the pipeline as per:

  • FigmaToken as your Figma API token
  • FigmaUrl to point to your Figma file ID

Set both to be secret values.

NOTE: It seems only template parameters in the Azure API work, and not the variables. See https://stackoverflow.com/questions/60852825/azure-devops-yaml-pipeline-parameters-not-working-from-rest-api-trigger?rq=1 for more.

Authentication

It seems the best way to authenticate is through Personal Access Tokens. Create one at your DevOps org site, i.e. https://dev.azure.com/YOUR_USER/_usersSettings/tokens. A suitable access scope is Build > Read & execute.

You will need the "pipeline ID" (or definition number) before calling the API. The easiest way is to navigate to your pipeline in the Azure Devops web console and check the URL bar which should look like: https://dev.azure.com/YOUR_USER/YOUR_PROJECT/_build?definitionId=16.

Solution from https://github.com/MicrosoftDocs/azure-devops-docs/issues/3263.

Example call to API

Use basic authentication with any username and your password as the Personal Access Token value you created previously.

Set the following header:

  • Content-Type: application/json

Then send a payload:

POST https://dev.azure.com/YOUR_USER/YOUR_PROJECT/_apis/pipelines/DEFINITION_NUMBER/runs?api-version=6.0-preview.1

{
  "resources": {
    "repositories": {
      "self": {
        "refName": "refs/heads/main"
      }
    }
  },
  "templateParameters": {
    "FIGMA_VERSION": "something-here-alright",
    "FIGMA_MESSAGE": "This is what happened"
  }
}

You can use refName to point to any relevant branch.

References

About

This is a basic demonstration of what is needed to run a Azure DevOps CI build by calling their REST API. We are using Figmagic for this demo, to demonstrate running it in CI.

Topics

Resources

Stars

Watchers

Forks