Release Variables through REST API - Visual Studio

2019-07-02 08:03发布

问题:

Is it possible to pass variable values to the REST endpoint for Release Management in VSTS? E.g. Calling PUT https://tfs.vsrm.visualstudio.com/defaultcollection/{project}/_apis/release/releases/30?api-version=3.0-preview.4 with the request of:

{
  "id": 30,
  "name": "Release-3",
  "variables": {
    "VariableName": {
      "value": "testing123"
    }
  }
}

I somehow managed to get it to work if I call POST https://k2tfs.vsrm.visualstudio.com/density/_apis/release/releases/?api-version=3.0-preview.4 then take that response and use it in the request above. Is this the only way?

回答1:

There isn’t the way to change variable value when create a new release.

Regarding your way, it modifies the created release variable value, the changed value can be used when deploy the release.

Another way is that, you can create a draft release,

Post:

https://[account].vsrm.visualstudio.com/[project]/_apis/release/releases/?api-version=3.0-preview.4

application/json:

{
  "definitionId": [release definition id],
  "isDraft":true
}

then update variables’ value (as you said)

after that, you can start the release by Modifying the status of a release (active)

{
    "status": "Active"
}


回答2:

Now you can define VSTS Release variables to be "Settable at release time". Then passing variable values at the time of creating a release is possible in VSTS REST API. You can do same when you try to Create a release in VSTS WEB UI as well. for more information refer this answer here.