7

I'm using TFS 2015.2 RTM and I just found out that the Release Management vNext REST API is in 2.2-preview.1 on-premises. I want to create a release, but I don't know the exact JSON to put in the body of the POST request since the documentation only works for VSTS.

When I send the request, I get the error message:

VS402881: No artifact version is specified corresponding to artifact source 'MyBuild.' Specify a valid value and try again. 

Here's the JSON:

$body = @"
     {
          definitionId": 1,
    "description": "test",
    "artifacts": [ 
      {
         "alias": "Tailspin Toys", 
         "version": {
               "id": 147,
         },
         "instanceReference": {
            "id": 5
        }
       }
     ]
} 
"@

And here's the Invoke-RestMethod command:

$releaseResponse = Invoke-RestMethod -Method Post -Credential $credential -ContentType application/json -Uri $postUri -Body $body

What JSON items am I missing? How do I find what to put in the JSON body if the docs don't have what is missing?

m00nbeam360.0
  • 1,342
  • 1
  • 13
  • 26
  • The RM REST API is not officially launched for on-premise TFS. You can use Fiddler to see exactly what JSON body is used. – ds19 Apr 15 '16 at 04:51
  • Interesting! I downloaded Fiddler4 earlier but could only find the JSON error message and not what body to use. Do you know how I can see the JSON body used? Sorry, have only used the tool a couple of times. :) – m00nbeam360.0 Apr 15 '16 at 06:18

4 Answers4

6

Yes there are some disparities between the current version of VSTS APIs and the TFS 2015.2 APIs. But most of the APIs should work except a very few. Here is the documentation link.

Following is the required JSON for creating a release. The required JSON needs to have the name in instanceReference although its optional for the current version of VSTS API.

{
  "definitionId": 1,
  "description": "test",
  "artifacts": [
    {
      "alias": "Tailspin Toys",
      "instanceReference": {
        "id": "5",
        "name": "<build_name>"
      }
    }
  ]
}
Harshil Lodhi
  • 7,274
  • 1
  • 33
  • 42
  • Interesting! I'll check that tomorrow morning. – m00nbeam360.0 Apr 15 '16 at 06:19
  • Great, worked like a charm! Do you know specifically which requests in TFS 2015.2 don't work so I know as a heads-up? – m00nbeam360.0 Apr 15 '16 at 17:11
  • I will have to do some work to gather it. I will try to do that and blog that till then you can almost safely follow VSTS docs. – Harshil Lodhi Apr 15 '16 at 19:11
  • Yes name need to be specified. However it is not very logical, as it is marked as optional in the documentation, and the name should be retrieved by TFS from the id of the build. We can set anything as value and it is accepted. – gentiane Jul 19 '16 at 13:25
  • @HarshilLodhi Do you how the `instancerefernce` schema needs to change to repository artifacts (instead of build artifacts)? Code you shared is working fine for all referenced artifacts that come from builds, but doesnt pick the version for repo artifacts (just uses empty version) which then never passes. – Arnab Chakraborty Jun 09 '21 at 23:54
0

Based on my Fiddler capture:

{
  "id": 0,
  "name": "xxx",
  "createdOn": "2016-04-15T06:48:14.173Z",
  "createdBy": null,
  "modifiedBy": null,
  "modifiedOn": null,
  "environments": [
    {
      "id": 0,
      "name": "Default Environment",
      "rank": 1,
      "deployStep": {
        "id": 0,
        "tasks": [ ]
      },
      "owner": {
        "displayName": "foobar",
        "id": "c236ac37-97ee-4ed0-b731-36ebb4a9ed3f",
        "isContainer": false,
        "uniqueName": "ad\foobar",
        "imageUrl": "http://tfs:8080/tfs/collection/_api/_common/IdentityImage?id=c236ac37-97ee-4ed0-b731-36ebb4a9ed3f&t=1460698957392&__v=5",
        "url": "http://tfs:8080/tfs/collection/"
      },
      "queueId": 1,
      "demands": [ ],
      "conditions": [ ],
      "variables": { },
      "runOptions": { "EnvironmentOwnerEmailNotificationType": "Always" },
      "executionPolicy": {
        "concurrencyCount": 0,
        "queueDepthCount": 0
      },
      "preDeployApprovals": {
        "approvals": [
          {
            "rank": 1,
            "isAutomated": true,
            "isNotificationOn": false,
            "id": 0
          }
        ],
        "approvalOptions": null
      },
      "postDeployApprovals": {
        "approvals": [
          {
            "rank": 1,
            "isAutomated": true,
            "isNotificationOn": false,
            "id": 0
          }
        ],
        "approvalOptions": null
      }
    }
  ],
  "artifacts": [ ],
  "variables": { },
  "triggers": [ ],
  "releaseNameFormat": "Release-$(rev:r)",
  "retentionPolicy": { "daysToKeep": 60 }
}
ds19
  • 3,176
  • 15
  • 33
  • Hmm, that's interesting. Almost looks like the GET request. I don't believe that the whole capture would go into the request, but I think that would help with getting a good start for it. – m00nbeam360.0 Apr 15 '16 at 17:13
0

For a similar error VS402962: No artifact version ID is specified corresponding to artifact source 'My build name'. Specify a valid value and try again.

I did what this article suggested...

refresh the page and try again

Homer
  • 7,594
  • 14
  • 69
  • 109
-1

You may take a look into the sample usage http://blogs.msdn.com/b/chandananjani/archive/2016/04/15/using-releasemanagement-rest-api-s.aspx

  • Link-only answers are frowned upon on Stack Overflow, as links tend to disappear as time goes on. If a link contains relevant information, include it in the body of the answer in addition to the link. That way, the answer will remain relevant and useful even if the link no longer works. – Daniel Mann Jun 07 '16 at 02:20