Azure DevOps API: get all testcase steps - azure

Is there a way to get all the testcase steps data via Azure DevOps API?

I was able to find the solution:
GET https://{host}/{collection}/{project}/_apis/testplan/Plans/{plan id}/Suites/{suite id}/TestCase/{testcase id}

You need to use this particular Endpoing,
POST https://dev.azure.com/{organization}/{project}/_apis/test/Runs/{runId}/results?api-version=5.0
and access TestActionResultModel

The Azure DevOps api has endpoints for returning test runs, results and cases. The api is wrapped in a PowerShell module called AzurePipelinesPS that has functions like
Get-APTestSuiteList
Get-APTestRunList
Get-APTestRun
Get-APTestRunStatistic
Get-APTestResultList
Get-APTestResult
Get-APTestPlanList
The following command will return a list of all your test cases in a suite.
Get-APTestSuiteList -Session 'youSessionName'
Be sure to setup a session locally with New-APSession when first installing the module. You can find the session documentation here.

Related

Azure Machine Learning pipeline: How to retry upon failure?

So I've got an Azure Machine Learning pipeline here that consists of a number of PythonScriptStep tasks - pretty basic really.
Some of these script steps fail intermittently due to network issues or somesuch - really nothing unexpected. The solution here is always to simply trigger a rerun of the failed experiment in the browser interface of Azure Machine Learning studio.
Despite my best efforts I haven't been able to figure out how to set a retry parameter either on the script step objects, the pipeline object, or any other AZ ML-related object.
This is a common pattern in pipelines of any sort: Task fails once - retry a couple of times before deciding it actually fails.
Does anyone have pointers for me please?
Edit: One helpful user suggested an external solution to this which requires an Azure Logic App that listens to ML pipeline events and re-triggers failed pipelines via an HTTP request. While this solution may work for some it just takes you down another rabbit hole of setting up, debugging, and maintaining another external component. I'm looking for a simple "retry upon task failure" option that (IMO) must be baked into the Azure ML pipeline framework and is hopefully just poorly documented.
I assume that if a script fails, you want to rerun the entire pipeline. In that case, it is pretty simple with Logic Apps. What you need is the following:
You need to make a PipelineEndpoint for your pipeline so it can be triggered by something outside Azure ML.
You need to set up a Logic App to listen for failed runs. See the following: https://medium.com/geekculture/notifications-on-azure-machine-learning-pipelines-with-logic-apps-5d5df11d3126. Instead of printing a message to Microsoft Teams as in that example, you instead invoke your pipeline through its endpoint.
(this would ideally be a comment but it exceeded the word limit)
#user787267's answer above help me set up the re-try pipeline. So I thought I'd add a few more details that might help someone else set this up.
How to set up the HTTP action
Method: POST
URI: The pipeline endpoint that you configured
Headers: `Key`: Content-Type -- `Value`: application/json
Body:
{
"ExperimentName": "my_experiment_name",
"ParameterAssignments": {
"param1": "value1",
"param2": "value2" },
"RunSource": "SDK"
}
Authentication Type: Managed Identity
Managed Identity: System-assigned managed identity
You can set up the managed identity by going to the logic app's page and then clicking on the Identity tab as shown below. After that just follow the steps. You'll need to give the managed identity permissions over the space in which your ML instance lives.

How to test Azure Data factory linked service using API

I am trying to create and use Azure data factory by Rest API but while creation of linked service connection has created successfully but when I checked connection it got failed so is there anything to do test connection by API or PowerShell command.
There is no this method in Microsoft documentation.You can track this feature here.
But there is a blog about testing link service by PowerShell.Here is the script on github.
Hope this can help you.
Now, you can use one of cmdlet in azure.datafactory.tools PowerShell module:
Test connection of Linked Service (preview)
# Example 1
$LinkedServiceName = 'AzureSqlDatabase1'
Test-AdfLinkedService #params -LinkedServiceName $LinkedServiceName
Alternatively, if you prefer, you can run such test as part of your CI/CD process in Azure DevOps installing #adftools extension, which uses the same PS module behind the scenes.
More: https://sqlplayer.net/adftools
Disclaimer: I'm author of the tool.

Create Azure Devops environment from script

I would like to create an Azure DevOps Pipeline Environment from Powershell.
Using Azure CLI or the Azure REST API however, I can not find any information on this.
There are some notions about the environments in the release but that's not what I need.
When using the portal following URL is called "/_apis/distributedtask/environments" but can't find any information about this REST API endpoint.
Does anyone know how to automate this?
You're right, If I check the network section when I create a new environment I can see it uses this api:
https://dev.azure.com/{org}/{project}/_apis/distributedtask/environments
With this JSON body:
{
"description":"",
"name":"test"
}
I don't see it domunetd but it should work :)

Using powershell, how do I create an api for an api management service with a version in path segment?

I can create an api using powershell as follows
New-AzureRmApiManagementApi -Context $azContext -ApiId $apiId -Name $apiName -ServiceUrl "https://myapp-dev-apims.azure-api.net/${subDomainName}" -Protocols #("https") -Path $subDomainName
However, this cmdlet does not create a version. It appears I need to use
New-AzureRmApiManagementApiVersionSet
However, Its not well documented how to do this when looking to add a version using a path segment such as myApi.com/cart/v1.
When creating the version within the portal, it says "Versioning creates a new API. This new API is linked to your existing API through a versioning scheme. Choose a versioning scheme and choose a version number for your API:"
Do I need to create a new api using New-AzureRmApiManagementApi, again a second time? This is confusing.
The workaround to this is to just use the New-AzureRmApiManagementApi cmdlet to initially create the api, then go into the portal to MANUALLY create the version. But it would obviously be nice if the process of creating both the api and its version were repeatable in a script.
Using powershell alone, how do I both create an api, and the version in one script? Help is appreciated. Thank you.
When creating the version within the portal, it says "Versioning creates a new API. This new API is linked to your existing API through a versioning scheme. Choose a versioning scheme and choose a version number for your API:"
It says correct, if you Add version in the portal, it will create a new API, just in the UI, it appears like under the original API. You could check them clearly in the resource explorer, there will be a "apiVersion": "xx"in the api version. After you adding a version, it will add a new API in the apis, and automatic create a version set in the api-version-sets, refer to the screenshot.
Per my test, the command New-AzureRmApiManagementApiVersionSet just create in the api-version-sets, and will not create in the apis, so you could not get what you want with it.
Also, I add version in the portal, and use Fiddler to catch the request, it essentially call the same REST API with creating a new API.
Some Workarounds for you to refer:
1.As you mentioned, create the api and add version in the portal manually.
2.Try to use New-AzureRmResource to create the api version.
3.Use the powershell Invoke-RestMethod to call the REST API.
To create a versioned API you first need to create a version set. You found the Powershell cmdlet for that. However, looking at New-AzureRmApiManagementApi it seems you cannot provide a versionsetid as parameter, which is needed to link the version set to the API.
With Powershell alone I don't think it's possible what you're trying to achieve, but what you could consider is using ARM templates.
These templates can be kicked off by Powershell and do provide the option to create an entire versioned API in one script.
For inspiration you could take a look at this blog post:
https://blog.eldert.net/api-management-ci-cd-using-arm-templates-linked-template/

Get Instance Count of Azure Web App with C#

I've been looking around and I can't find a concise example around getting this metric. I've installed WindowsAzure.Management.Compute and now I don't know where to begin. How can this be done?
I would recommend you to take a look at Azure Resource Explorer: https://resources.azure.com. You could find the instances request URL as following:
For the Authorization header please have a look at this article. We can use C# HttpRequest to write the code. Here is the result I tested in fildder.
the endpoint:
https://management.azure.com/subscriptions/<subscription id>/resourceGroups/jatestgroup/providers/Microsoft.Web/sites/testcore1/instances?api-version=2015-08-01
Result:
We can calculate the instance number from the response json. In addition, it will need a long time in this rest API to show all instances when scale the instance in azure portal.
[Update]
According with my comment, I tested with the article:http://blog.amitapple.com/post/2014/03/access-specific-instance/#.V9tLKyh95hF
The following is my result:
Please download the library at here. Refer to this article for more information about Windows Azure Management Certificates.
Here is the code snipped:
var cert = new X509Certificate2();
cert.Import(Convert.FromBase64String(""));
var _client = new Microsoft.WindowsAzure.Management.WebSites.WebSiteManagementClient(new Microsoft.WindowsAzure.CertificateCloudCredentials("****", cert));
var ids= await _client.WebSites.GetInstanceIdsAsync("EastAsiawebspace", "testcore1");
You cannot get the instance count from within one instance of the Web App. But you can get it from the portal, or from the Azure ARM API (it's the numberOfWorkers property on the Web Hosting Plan object).
Also, note that WindowsAzure.Management.Compute does not apply to Azure Web App.

Resources