Cannot access deleted builds using the TFS 2015 REST API - rest

Using the older TFS API, it's possible to access deleted builds using the following code:
IBuildDetailSpec buildDetailSpec = buildServer.CreateBuildDetailSpec(m_teamProject, m_buildDefinition);
buildDetailSpec.BuildNumber = (string.IsNullOrEmpty(m_buildPrefixOverride))? m_buildDefinition + "*" : m_buildPrefixOverride + "*";
buildDetailSpec.MaxBuildsPerDefinition = m_maxBuildPerDefinition;
buildDetailSpec.Status = BuildStatus.All;
buildDetailSpec.QueryDeletedOption = QueryDeletedOption.IncludeDeleted;
buildDetailSpec.QueryOrder = BuildQueryOrder.StartTimeDescending;
buildDetailSpec.InformationTypes = null;
IBuildQueryResult buildQueryResult = buildServer.QueryBuilds(buildDetailSpec);
On the other hand, it seems impossible to query that same thing using the TFS 2015 Update 2 (on-premise) REST API according to the documentation.
This is the query I'm running:
http://tfsserver:8080/tfs/defaultcollection/BuildTools/_apis/build/builds?api-version=2.0&definitions=1227
Did anyone manage to query them? If so, how?

REST API doesn't include query deleted option like .Net API IBuildDetailSpec.QueryDeletedOption.
When get a list of builds for a build definition, REST API below only output the builds not deleted:
http://tfsserver:8080/tfs/defaultcollection/BuildTools/_apis/build/builds?api-version=2.0&definitions=xx
You may consider submit a user voice at website below: https://visualstudio.uservoice.com/forums/121579-visual-studio-2015

Related

How do I give Permissions using Azure DevOps Server Rest APi

https://learn.microsoft.com/en-us/rest/api/azure/devops/security/?view=azure-devops-server-rest-5.0
https://learn.microsoft.com/en-us/rest/api/azure/devops/security/access%20control%20entries?view=azure-devops-server-rest-5.0
Hi there, I'm having problems with trying to understand the way to set up permissions using the API in ADO 2019. I can see what the security namespace one API does. I can get bitwise that relates to, for examples, git repos. I can't see how to add permissions to a user or group. e.g. I can't see how to get a bitwise that has multiple permissions, do I just add them together? I can see the API that says how to add ACEs but that doesn't actually tell me how to add permissions really. I'll try to explain.
If I run the API for ACL , I get a pile of info back, one of which is token.
Okay, so surely if I get the GUID for the git repo using the git API to list them, the GUID will match up with the ID's in the token like the namespaces do. Nope.
The examples don't seem to be actual examples. I'm looking for 'If you have a git repo , here's how you would give someone permissions to it' 'here's an example of getting the existing permissions for a group and adding another'.
Instead it's just
'here's a string of guids getting put into the API' without explaining the pieces or what specifically it was doing. I can't seem to relate what's in the GUI for adding perms, to what the security API is bringing back.
Am Azure DevOps on prem so I'm more limited in tool selection. Other people I've asked say they gave up trying to use this. AzureDevops on twitter says I can connect with the team here. I'm asking how to do things with the security API and then I can go write it up and suggest how to update the docs. I'm clearly too thick to figure it out from what's there and I don't seem to be the only one. Thanks
For Azure DevOps Service, you can manage group membership using Graph API. But this api is not available for Azure DevOps Server.
In my opinion, for on-premise TFS/Azure DevOps Server, TFSSecurity command line is easier than TFS API to add permissions for a user or a group in a server-level, collection-level, or project-level group. You may consider using TFSSecurity command line:
https://learn.microsoft.com/en-us/azure/devops/server/command-line/tfssecurity-cmd?view=azure-devops-2019
You may also check the following code to get the permissions:
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Server;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.Framework.Client;
namespace API
{
class Program
{
static void Main(string[] args)
{
string project = "http://xxx.xxx.xxx.xxx:8080/tfs";
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(project));
var tps = tpc.GetService<VersionControlServer>();
var ttt = tps.GetTeamProject("ProjectName");
ISecurityService securityService = tpc.GetService<ISecurityService>();
System.Collections.ObjectModel.ReadOnlyCollection<SecurityNamespace> securityNamespaces = securityService.GetSecurityNamespaces();
IGroupSecurityService gss = tpc.GetService<IGroupSecurityService>();
Identity SIDS = gss.ReadIdentity(SearchFactor.AccountName, "GroupName", QueryMembership.Expanded);//GourName format: [ProjectName]\\GourpName
IdentityDescriptor id = new IdentityDescriptor("Microsoft.TeamFoundation.Identity", SIDS.Sid);
List<SecurityNamespace> securityList = securityNamespaces.ToList<SecurityNamespace>();
string securityToken;
foreach (SecurityNamespace sn in securityList)
{
if (sn.Description.DisplayName == "Project")
{
securityToken = "$PROJECT:" + ttt.ArtifactUri.AbsoluteUri;
sn.SetPermissions(securityToken, id, 115, 0, true);
}
}
}
}
}

How to publish a draft Task Group via Azure DevOps API

I am in the process of converting some tasks inside numerous task groups we have to different tasks. Instead of doing this by hand I've opted for using Powershell along with the Rest API of Azure DevOps to update the JSON bodies of these task groups and send them to the API. The conversion of the tasks is working fine sofar.
sending a PUT to the rest API in order to update the current task group of the set works but I want to build in some retention / version history if some of the new tasks end up working different than expected. So just blatantly updating the existing Task Group under the same major version is not an option.
the UI of Azure DevOps has functionality where you can save changes to a task group as a 'draft' and then publish this draft as either a completely new version (major version + 1) or as a preview
I went ahead and attempted to send a PUT to the Rest API and upticking the major version using the following URI:
PUT https://dev.azure.com/{organization}/{project}/_apis/distributedtask/taskgroups/{taskGroupId}?api-version=5.1-preview.1
Along with the settings:
JSONObject.version.major = $currentversion + 1
JSONObject.preview = true
This results in the API returning an error saying:
Invoke-WebRequest : {"$id":"1","innerException":null,"message":"Task group {TaskGroupID} not found.","typeName":"Microsoft.TeamFoundation.DistributedTask.WebApi.MetaTaskDefinitionNotFoundException, Microsoft.TeamFoundation.DistributedTask.WebApi","type
Key":"MetaTaskDefinitionNotFoundException","errorCode":0,"eventId":3000}
I then went ahead and tried to see if I could create a draft version. When sending a POST to the following URI i was able to create a draft:
POST https://dev.azure.com/{organization}/{project}/_apis/distributedtask/taskgroups?api-version=5.1-preview.1
using the following settings in JSON:
JSONObject.version.major = 1
JSONObject.version.istest = true
JSONObject.id = $null
JSONObject.parentDefinitionId = {TaskGroupID of the taskgroup of which i am trying to make a draft}
This nets in a new Task group in draft state which i am able to view in the UI and modify and publish (with or without preview). When i export the created JSON from UI from a manually made draft and compare it versus the one coming from powershell i see no differences.
This last step is where I am stuck. I can't seem to convert the created draft into a new version of the {parentdefintionid} task group. I've tried the following settings:
Calling the taskgroupid URI of the parent with put while a draft is available
JSONObject.version.major = $currentversion + 1
JSONObject.version.isTest = false
JSONObject.preview = true
Removing ParentDefinitionID from JSONObject
is resulting in the same error where it states that it cannot find the ID of the parent:
Invoke-WebRequest : {"$id":"1","innerException":null,"message":"Task group {TaskGroupID} not found.","typeName":"Microsoft.TeamFoundation.DistributedTask.WebApi.MetaTaskDefinitionNotFoundException, Microsoft.TeamFoundation.DistributedTask.WebApi","type
Key":"MetaTaskDefinitionNotFoundException","errorCode":0,"eventId":3000}
The same is valid with above settings and calling the draftID URI
When i try to call the draftID task group URI with the following settings :
JSONObject.version.major = $currentversion + 1
JSONObject.version.isTest = false
JSONObject.preview = true
JSONObject.id = $ParentDefinitionID
Removing ParentDefinitionID from JSONObject
it results in the following error:
Invoke-WebRequest : {"$id":"1","innerException":null,"message":"The request specifies task group ID {parentTaskGroupID} but the supplied task group has ID {DraftTaskGroupID}.","typeName":"Microsoft.TeamFoundation.DistributedTask.WebApi.Task
GroupIdConflictException, Microsoft.TeamFoundation.DistributedTask.WebApi","typeKey":"TaskGroupIdConflictException","errorCode":0,"eventId":3000}
i've checked the actual JSONObject to an export of a published Task Group in UI and they match exactly so i'm quite positive that content is not the issue here.
The MS documentation is seriously lacking on API usage so i'm really in the dark there hoping to find some clues / solution here
Seems you were updating a already exist task group in Azure DevOps.
If you incremented the revision property to be 1 higher than what is currently deployed.
You need to submit the JSON with the same revision property that the server has.

TFS Rest API 2018: how to query SharedSteps and TestCase through TestManagementHttpClient

I am using this code to get sharedsteps and testcase through testmanagement using TFS OM API.
But how can i query SharedSteps and testcase using TestManagementHttpClient in TFS REST API 2018 , kindly suggest me.
string batchQuery = "SELECT * FROM workitem where Id IN (22233,21425,24512) ORDER BY [Id] desc";
ITestManagementService testManagementService = (ITestManagementService)_teamProjectCollection.GetService(typeof(ITestManagementService));
ITestManagementTeamProject _testManagementProject = testManagementService.GetTeamProject(Name);
List<ISharedStep> sharedStepsWIList = _testManagementProject.SharedSteps.Query(batchQuery).ToList();
List<ITestCase> tfsTestCaseCol = _testManagementProject.TestCases.Query(batchQuery).ToList();
There is no method in TestManagementHttpClient to get test cases and shared steps.
Test Case and Shared Steps are work item types, so you can use the Query method in Microsoft.TeamFoundation.WorkItemTracking.WebApi.WorkItemTrackingHttpClient to get these information.

TFS 2015 On Premise REST API 404 searching test runs or results

Using the TFS 2015 REST API to try to get test runs and results with 404. When fetching projects or teams it works fine.
var uri = $"http://tfsserver:8080/tfs/project/_apis/test/runs/1994/results";
using (WebClient wc = new WebClient())
{
wc.UseDefaultCredentials = true;
wc.Credentials = CredentialCache.DefaultCredentials;
var result = wc.DownloadString(uri);
Console.WriteLine(result);
}
Console.Read();
The following URLs do not work: (NOTE: I removed the server portion because of a limitation of stackoverflow)
.../tfs/project/_apis/test/runs
But these do work:
.../tfs/project/_apis/projects/CodedUi/teams
.../tfs/project/_apis/projects
You are using the wrong url, lack of team project collection name.
http://tfsserver:8080/tfs/Yourcollection/project/_apis/test/runs/1994/results?api-version=1.0
And since there are two versions of API 1.0,3.0, suggest you also add the related API version. More details please refer this tutorial: Get a list of test results

Rally Web Soap service - get a list of test cases and who created them

I need to get a list of all of the test cases in Rally along with the person who either created them or last modified them.
I thought I could achieve this by getting the changeset but that doesn't appear to have worked - I seem to get a lot of test cases that don't have any changesets at all
String myQuery = "(Method = Manual)";
QueryResult myArtifactReturn = m_rallyService.query(myWorkspace, "TestCase", myQuery, "", true, 0, 100);
long mycount = myArtifactReturn.TotalResultCount;
if (mycount > 0)
{
myArtifact = (TestCase)myArtifactReturn.Results[0];
myArtifact = (TestCase)m_rallyService.read(myArtifact);
Changeset myInitial = (Changeset)m_rallyService.read(myArtifact.Changesets[0]);
}
Is there a way I can do this?
Or is there a way to query Rally to ask for 'all test cases created by User X'?
Thanks
I think you might be mixing up ChangeSets with RevisionHistory. If you're looking to track Revisions on a Rally Artifact, you should look at the RevisionHistory collection. ChangeSets are used by Rally's source code connectors to associate source code commits to various artifacts in Rally.
You might find this answer:
RevisionHistory and Revisions
Instructive for dealing with RevisionHistory in SOAP. The example is for User Stories, but is equally applicable to Test Cases.
Unfortunately, you can't query on RevisionHistory, so you would need to retrieve all the Test Cases that could potentially have matches against your search, and do the filtering for the TestCase creator in your SOAP client. You would need to check the Author attribute for Revision 0:
0 Original revision
2013-Feb-18 09:23:11 AM America/Denver Sam Tester
And verify that it matches your criteria.
Just a heads-up, especially if you're just getting started with building your integration, I'd highly recommend using one of Rally's .NET REST SDK instead of SOAP.
REST is more robust, more performant, and, Webservices API 1.43 was the final API release to have SOAP support, and 1.43 has about 9 months to go (as of 9/2013) before deprecation. Webservices 2.x is REST-only, so using REST will be essential to anyone wanting new Webservices features moving forward.