not able to delete test cases in azure devops through powershell scripts

夙愿已清 提交于 2021-01-28 13:36:45

问题


I have checked How to delete multiple test cases in Azure DevOps

It not works for me.

Using PowerShell scripts alone, I want to delete multiple test cases in one go in Azure DevOps. Currently, portal only allows to delete one at a time.

I have tried like below way, and throws exceptions.

$url = "https://dev.azure.com/testarulmouzhie/testDemo_Project/_apis/test/testcases/21?api-version=5.0-preview.1"
Invoke-RestMethod -Uri $url -Method Delete -ContentType application/json

it throws error like below one-

Even tried with the new api version, same error comes-

$url = "https://dev.azure.com/testarulmouzhie/testDemo_Project/_apis/test/testcases/21?api-version=5.1-preview.1"
Invoke-RestMethod -Uri $url -Method Delete -ContentType application/json

Attached the error for ref-

Invoke-RestMethod :
Azure DevOps
Service Status Support @AzureDevOps
At line:1 char:1
+ Invoke-RestMethod -Uri $url -Method Delete -ContentType application/json
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
   eption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Can anyone help to solve this? Thanks in advance.

For ref, anyway simple GET rest api calls works fine. i have tried below one and those are working fine.

$AzureDevOpsPAT = "a2wzly2bsirXXXXXXXXXXXXXXXXXXXXXXXXXXX"
$OrganizationName = "testarulmouzhie"

$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($AzureDevOpsPAT)")) }

$UriOrga = "https://dev.azure.com/$($OrganizationName)/" 
$uriAccount = $UriOrga + "_apis/projects?api-version=5.1"

Invoke-RestMethod -Uri $uriAccount -Method get -Headers $AzureDevOpsAuthenicationHeader

Even used fiddler and tried to capture error logs- attached those too


回答1:


Ah I think you have missed your the autorizationheader in your delete Invoke API

Please include the -Headers $AzureDevOpsAuthenicationHeader like below

--give below your pat access token

$AzureDevOpsPAT = "ukcvd42u5rXXXXXXXXXXXXXXXXXXX";
$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($AzureDevOpsPAT)")) };
$url = "https://dev.azure.com/testarulmouzhie/testDemo_Project/_apis/test/testcases/21?api-version=5.0-preview.1"
Invoke-RestMethod -Uri $url -Method Delete -ContentType application/json -Headers $AzureDevOpsAuthenicationHeader;

As Leo suggested it also maybe with the license, so how to check your license for the test cases?




回答2:


not able to delete test cases in azure devops through powershell scripts

It seems you do not have the Test Plans license to use the REST API Test Cases - Delete.

Azure Test Plans uses an access level called Basic + Test Plans, you need a Basic + Test Plans license to manage the test plans and test suites, etc. Please check the following link:

Manual test permissions and access

Here are two ways of ensuring you have the right license.

1) The user is assigned a test manager extension license - https://marketplace.visualstudio.com/items?itemName=ms.vss-testmanager-web

2) The user has a VS Enterprise or Test Professional subscription

You can do this by accessing test hub and trying to add test cases directly there with the same user (account create the PAT)as is used in the REST API.

Check this thread for some details.

Hope this helps.



来源:https://stackoverflow.com/questions/62020297/not-able-to-delete-test-cases-in-azure-devops-through-powershell-scripts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!