0

I have a release definition in TFS 2018. For every environment, I can set pre-deployment approver(s) (AD group) in the GUI. I need to do this from code (preferably PowerShell).

Is there a way to do this? I did not find any way how to achieve this via REST API.

Petr
  • 182
  • 1
  • 4
  • 18

1 Answers1

0

You just need to use create a release definition API, and add approver in "preDeployApprovals" argument. Check the example below

"preDeployApprovals": {
  "approvals": [
    {
      "rank": 1,
      "isAutomated": true,
      "isNotificationOn": false,
      "approver": {
        "id": "4adb1680-0eac-6149-b5ee-fc8b4f6ca227",
        "displayName": "Chuck Reinhart",
        "uniqueName": "Domain\\username",
        "url": "http://TFS2018:8080/tfs/DefaultCollection/_apis/Identities/4adb1680-0eac-6149-b5ee-fc8b4f6ca227",
        "imageUrl": "http://TFS2018:8080/tfs/DefaultCollection/_api/_common/identityImage?id=4adb1680-0eac-6149-b5ee-fc8b4f6ca227"
      },
        "id": 0
      }
  ]
}, 
Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39
  • Thanks for answer! I was playing around with this. It works fine, but problems are "id" properties (and may be others as well). I do not know where to get them. I did not find any API method that gets them. My task is simply "add account Domain\username to release definition id 1 to all environments". – Petr Jan 26 '18 at 15:48
  • You can't just use `Domain\username` in this api, `id` is required. You could create a release definition and select the approvers used frequently in UI, and use [Get a release definition](https://www.visualstudio.com/en-us/docs/integrate/api/rm/definitions#get-a-release-definition) api to get the ids and store them locally. – Cece Dong - MSFT Jan 29 '18 at 03:33
  • This wouldn't be very flexible solution. Such a script will stop working after someone will want to set a person not in the list (e.g. new employee in operations team). – Petr Jan 29 '18 at 08:03
  • How about get the info through [Get a team's members API](https://www.visualstudio.com/en-us/docs/integrate/api/tfs/teams#get-a-teams-members)? – starian chen-MSFT Jan 31 '18 at 08:46
  • @starianchen-MSFT thanks, this is the way to go. I still find the API for releasing a bit cumbersome. It is perfect when you need to add/remove a releasing definition as a whole. Problematic is operating on lower levels (add task to environment, add/remove approver etc.). – Petr Feb 15 '18 at 14:38