How do I delete shared steps in VSTS - tfs

I’m trying to programmatically delete shared steps (I am experimenting with export/import, and am generating a large amount, and want to be able to delete them – not manually, one at a time).
Shared steps, like all “hidden” category work item types, cannot be deleted with the delete work item API. Test cases, test plans, and test suites have special APIs to allow their deletion, but I cannot find a similar API for the shared steps.
Does any one know what the API is, or whether there is one, or whether there will be?

Yes, a shared step is actually a work item type under the covers.
Unlike test plan/suite, there is no related Rest API could directly delete them. Expect deleting manually through web portal. It can only be destroyed by using witadmin destroywi command which is the only available option right now.
Also works with VSTS, you just have to install any edition of VS , the command located at (%programfiles(x86)%\Microsoft Visual Studio 1x.0\Common7\IDE)
To run the witadmin command-line tool, open a Command Prompt window
where Visual Studio is installed. The witadmin command-line tool
installs with any version of Visual Studio.
You can access this tool
by installing the free version of Visual Studio Community.
You'll need to know the ID of the Shared Steps Work Item you want to get rid of.
witadmin destroywi /collection:https://xxx.visualstudio.com /id:123

Able to do via REST API now:
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($personalToken)"))
$header = #{authorization = "Basic $token"}
$sharedStepIdFileContent = Get-Content -Path .\SharedStepsIdList.txt
$sharedStepIdList = $sharedStepIdFileContent.Split([System.Environment]::NewLine, [System.StringSplitOptions]::RemoveEmptyEntries)
$sharedStepIdList | % {
$sharedStepId = $_
$url = "https://dev.azure.com/{org}/{project}/_apis/test/sharedstep/$($sharedStepId)?api-version=5.0-preview.1"
Write-Host "Deleting Shared Step $sharedStepId ..."
Invoke-RestMethod -Uri $url -Method Delete -ContentType application/json -Headers $header
}

Related

Get single workspace without prompt TFS command line

What I'm trying to do should be simple - I want to get information for a single TFS workspace (in this case named the same as the computer name), and have that information returned via text - not via prompt window (it's my understanding this is what the /noprompt option is for). I am using the "workspace" command, and according to the official documentation (https://learn.microsoft.com/en-us/vsts/tfvc/workspace-command), it's not 100% clear this is supported.
Note:
I have tf.exe from Visual Studio 2017 and 2015 installed, and the 2015 Power Tools, but am preferring the 2017 client.
I've read the TF Workspaces question, and view this as something else - I specifically want the information about a single workspace (for a PowerShell script).
The /noprompt option of tf.exe don't allow you to view details.
It allows you to create a new workspace or edit existing one, without the dialog.
You can use the tfs client object model to query local workspaces. You can get the local workspaces through the workstation object https://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.workstation(v=vs.120).aspx
And you can use the version control server object to query additional details, fetch files, change the mapping etc https://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.versioncontrolserver(v=vs.120).aspx
This blog explains how to load the right assemblies, it references the 12.0 object model, I'd reccomend using the latest nuget packages instead. https://www.google.nl/amp/s/alistairbmackay.wordpress.com/2016/02/01/manipulating-tfs-with-powershell-part-1-connecting/amp/
Latest object model:
https://www.nuget.org/packages/Microsoft.TeamFoundationServer.ExtendedClient/

vNext TFS 2015 Builds - Remove Changeset and Work Item Associations From Build, Then Re-add Them

Target Environment: TFS 2015 Update 3
We are attempting to get the vNext build system to allow us to to only associate Changesets and Work Items to a build once it is deployed via Release Management. However, the TFS vNext build system automatically associates these items to builds at build time (based on the last successful build). The old XAML build system had a property to turn this off called SkipGetChangesetsAndUpdateWorkItems, but it no longer exists in the new system.
Therefore, I need to add a task/script at the end of the vNext build process to remove these associations (and then add a similar task to Release Management to re-associate them). It's not the simplest task in the world, but it seems like something should be feasible via the TFS REST API.
However, I cannot for the life of me find out how these associations are formed. The JSON for the Changesets don't seem to mention an associated build, and the JSON for the build doesn't seem to mention a list of associated changesets.
How are these associations between Changesets/Work Items and builds defined?
There is no such Rest API can achieve this of remove changeset. In XAML build, the related info are stored in a SQL table called dto.tbl_BuildDefinition, for which you want to reassociate changesets and change values in LastBuildUri, LastGoodBuildUri and LastGoodBuildLabel . Details please refer this link: Re-associate changesets and work items with build For vNext build definition, I didn't find something similar in SQL. However there must be some somewhere stored the association.
For the association between workitem and build, there is a method called $WorkItemAssociatedURL such as
$WorkItemAssociatedURL = $collectionURL + $project + “/_apis/build/builds/” + $BuildId + “/workitems?api-version=2.0”
$ResponseJSON = Invoke-RestMethod -Uri $WorkItemAssociatedURL -ContentType “application/json” -headers $headers -Method GET
For more detail info you can refer this blog: Build association with work Items in vNext

How do I delete a shared parameter in Microsoft Test Manager

We are using Microsoft Test Manager 2015 Update 1. I created a couple of shared parameters to see how they work.
How do you delete them? I can make them inactive, but they still display in the list of available shared parameters. I don't see a delete button and when I searched online I found nothing about it.
Shared Parameters are stored in TFS as Work Items so you could destroy it (there may be a better way but I don't know of one)
Remove or delete work items
On-premise you'll have to use the witadmin.exe command line tool (%programfiles(x86)%\Microsoft Visual Studio 14.0\Common7\IDE) with the destroywi option. You'll need to know the ID of the Shared Parameter Work Item you want to get rid of.
witadmin destroywi /collection:http://TFSServerName:8080/tfs/DefaultCollection /id:123

How can I query a folder in TFS to show me the latest ChangeSet for each object?

Currently, our DBAs require the TFS changeset number for any scripts/stored procedures/functions that need to get deployed. I have a folder in our TFS project with all of my stored procedures in it, and I'd like to run a single query that will list each object in that folder and the latest changeset. I'm using VS2010 Team Explorer with TFS Server 2008 (I believe), and would be happy to script it in PowerShell or some other tool, but don't know where to begin. Can someone provide me some direction?
TFS has a lot of extensibility points that make running a query like this possible. If it were me, I'd simply use the tf.exe command-line client. For example:
tf properties $/Path/To/Folder -recursive
This will show you the latest changeset for each of the files beneath the given folder (as well as other information.)
While the output from the command-line client is well-formed and easily parseable, you may still prefer a more programmatic way to do it. You can use the very powerful .NET API in order to query from the server. You'll want to call the VersionControlServer.GetItems method. For example:
ItemSet items = vcs.GetItems(#"$/Path/To/Folder", RecursionType.Full);
If you haven't yet, you should take a look at the TFS 2008 Power Tools, which include the TFS Power Shell Extensions. My powershell-fu is weak, but I think that the above in Power Shell works out to be something like:
$tfs = get-tfs http://yourserver:8080/tfs/YourCollection
$tfs.VCS.GetItems('$/Path/To/Folder', $tfs.RecursionType::Full)

How to delete Work Item from Team Foundation Server

Is there a chance to delete Work Item from TFS, or all I can do is just to rename it.
Update:
This question was for TFS 2008.
New version (2010) have out of the box solution as Rob Cannon suggested
The answers here are obsolete for TFS 2010. You need to use the 'witadmin destroywi' command now.
http://msdn.microsoft.com/en-us/library/dd236908.aspx
See this tool: http://devmatter.blogspot.com/2009/04/deleting-work-items-in-tfs-ui.html
the Team Foundation Client does not include any functionality for deleting work items from TFS.
Although it’s a tad inconvenient, you can delete work items from TFS by installing the Team Foundation Server Power Tools (October 2008 release or greater). Of the many features available as part of the power tools, there is a command called destroywi that can be used to delete work items. For example, to delete the work item ID 1234, use the command:
tfpt destroywi /server:tfs-dev /workitemid:1234
Although this is a relatively straightforward task to perform, not everyone is comfortable with the command line interface not to mention you have to look up the work item ID(s) ahead of time. To ease the process a little bit, I created a simple UI that sits on top of the Team Foundation Server Power Tools that allows you to easily select a Team Foundation Server and Project to query from. You can run an existing query to display a list of work items from which you can select one or more work items to be deleted. You can also enter the work item IDs directly (as a comma-separated list) if you prefer...
No one added code or an example, so here is my re-iteration of this answer using Rob Cannon's answer as guidance above.
This is batch file code for accomplishing this task. You will be prompted before you actually delete your Work Item.
ECHO OFF
SET "VSDir=C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\"
CD %VSDir%
SET /p WorkItemID=Enter Work Item ID:
ECHO.
witadmin destroywi /collection:{TFS Server}/{Collection Name} /id:%WorkItemID%
ECHO.
PAUSE
Enjoy
If you want to do this without using the tool suggested in the accepted answer, here is a quick summary of what to do. This is based on the corresponding MSDN article suggested in another answer.
Open Visual Studio Command Prompt:
Using the start menu:
Search for it.
Or navigate to All Programs -> Microsoft Visual Studio X -> Visual Studio Tools to find it.
Invoke witadmin
Determine the team project collection URL. An example is http://ServerName:Port/VirtualDirectoryName/CollectionName.
Determine the work item id.
Invoke the following command, substituting the two above values:
witadmin destroywi /collection:CollectionURL /id:id
See the MSDN article for more details. Note that you need permission for this to work.
You have to use the TFS Power Tools.
http://msdn.microsoft.com/en-us/vstudio/bb980963.aspx
1) As mentioned above the destroy command (pretty tiresome if you have to delete more than a single item)
2) With TFS 2015.2 you get a new recycle bin function (without an option to permanently remove the items).
https://www.visualstudio.com/en-us/news/tfs2015-update2-vs.aspx#delwork
But since they dont appear anywhere (replaces the "Removed" State) and they can be restored ... compared to the fact that it took since 2008 to add the bin feature .. pretty neat id say :D

Resources