Accessing VSTS REST API – Get Release definition

As of the need to automate some tasks in VSTS, I was looking for a solution to access VSTS without any UI. To get this done,
I first used the VSTS CLI [
CLI Link] to do things right. But unfortunately CLI is not “complete” (missing e.g. Release mgt) and also I cannot install
VSTS CLI everywhere. With that in mind, I decided to use the full REST api [
Documentation], to get things done. Here are the steps to take, to get at least one release definition by use of REST
calls to VSTS:

Create a PAT (Personal Access Token) in VSTS, to gain Access…

  1. …by clicking on your profile Icon and choosing “Security”
  2. Next, click “Add” to generate a token
  3. Fill in the Name of your PAT, expiration days and so on. Under “Authorized Scopes” you should select “Selected Scopes”
    and check all relevant scopes, that you like to authorize.

With that, open Postman (or another tool, that you like or use)

what we will do here is first getting a list of all projects along with their ID

  1. Add the calling REST URI of following Format:
    https://[VSTS account instance].visualstudio.com/DefaultCollection/_apis/projects?api-version=2.0-preview.1
  2. select Authorization tab and type “Basic Auth”
  3. leave the “User” field empty
  4. add the new created PAT into “Password” field
  5. Make sure you have a GET Operation and click “Send” -> below in Postman-Window the resulting response of the REST
    call will be displayed.

the release definitions of a project, which we can use for further documentational Tasks

      1. Now, for getting the list of Release definitions, you have to read carefully the documentation on
        Visual Studio Doc . There is a documentation lag! There is the Definition of REST Api for retrieving
        the definitions as follows:
        GET https://{instance}/{project}/_apis/release/definitions?api-version={version}
        But it should be as in the examples (like so):
        GEThttps://fabfiber-inc.vsrm.visualstudio.com/MyFirstProject/_apis/Release/definitions
        notice the red vsrm
    1. with that, create a new REST call as a GET Operation by typeing URL in that Format:
https://[VSTS account instance].vsrm.visualstudio.com/[Project]/_apis/release/definitions

(you can also append the api version)

  1. With Authorization set, as before, you can send the call and get back a list of Release defionition in JSON Format
  2. For retrieving a single one with details, you have to pass a specific ID, from the list before, that you can pass as a parameter to the REST Api
    https://[VSTS account instance].vsrm.visualstudio.com/[Project]/_apis/release/definitions/1?api-version=4.0-preview.3
    

    ! as a  hint, don’t use any GUIDs. 🙂

That’s all! Now, you can analyse that resulting JSON or use it for further documentation. I will soon post an article, where I reuse this JSON to generate a readme.md for documentational reasons …

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.