Azure DevOps API work with releases states - azure-devops

I want to get releases, which state is only
in progress, but when I send request https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases?definitionId={definitionId}&api-version=5.1 to get all releases and see, which field is responsible for release state I see, that all releases have status active.
I thought I must use https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases?definitionId={definitionId}&statusFilter=active&api-version=5.1, but that is wrong way for my target task.
What should I use? Thanks you in advance!

That's because you're looking at the wrong API. You need to use the deployments API and specify deploymentStatus for querying the status of deployments.
The API you're using queries the overall status of a given release, not the individual stages. The JSON returned contains information about the stages, but you can't filter the stages based on their current status with that API.

Related

How to fetch all the deployments completed after the given timestamp using Azure Devops REST Api?

So there is List Release Deployments API. It allows to get all the deployments started after the given timestamp. However, how to get those completed after it?
Rationale
Suppose I want to write a scheduled job that fetches information about completed deployments and pushes it to an Azure Application Insights bucket (for example for DORA metrics). I do not understand how it can be done easily without the ability to filter by the completion date. A relatively hard way would be to fetch by the started date, notice all the deployments inProgress or notDeployed and record them in a dedicated database. Then on the next polling cycle fetch new deployments and all those still recorded in the aforementioned database. This is much more complicated than it could have been with the ability to filter by the completion date.
Am I missing anything here? Maybe there is a simpler way (possibly using another API) that I just do not see?
EDIT 1
By the way, the hard way is even harder than I thought, since apparently there is no way to fetch release deployments by their Id.
EDIT 2
The plot thickens. If a stage has post deployment approvals, then the stage is reported as inProgress, even though de facto it has already been deployed. So an API that just filters by completion date would omit such deployments. It has to be with an option to include such deployments.

How to get sprint wise automated test cases in Azure devops system?

I am in need of getting some automation metrics like, what are the test cases automated in a specific time period in ADS. I tried the below query.
The challenge with this query is: it is retrieving the automated test cases which were automated before this duration. It is because their other attributes are changed like: Title, some tags etc. I was looking for some field that stores the information like(Automated Test Id, Automated Test Name, Automated Test Storage, Automation status). But I didnt' see this. I tried to use "History" field, but that didn't work as it is not populated the automation information in history field.
Any thoughts please?
enter image description here
How to get sprint wise automated test cases in Azure devops system?
At this moment, we could not query the History with State changed from one state to another state on Web UI directly.
As workaround, we could add a custom field in our custom process that gets set the value to true when workitems state change from X to Y.
Then add a Rules to set the value of the custom field to True if the workitems state change from X to Y.
Finally, we could query the workitems with custom field status.
You could check this thread for some more details.
Besides, you can also try do it through PowerBI. Calculate time-in-state for an existing Analytics view.

How to invoke iteration API query in Azure DevOps Services

I am trying to invoke the Rest API below for getting list of work items which are mapping to a specific iteration.
https://learn.microsoft.com/en-us/rest/api/azure/devops/work/iterations/get%20iteration%20work%20items?view=azure-devops-rest-5.1
Ultimately I want to invoke this as part of the Approval step in my Release pipeline so that the approver can verify if all work items for a given iteration are in Completed state.
I have two questions:
I don't know how to get the values for {team} and {iterationid}
How do I invoke this API as part of the approval gate. Should I use a Generic service connection? What user name and password do I need to provide?
Any working example here will be really helpful.
To get teams, you can use Teams - Get Teams on Team Project.
Then you can find all team iterations and their ids Iterations - List
You can use gates with azure function. Here is the example: Azure DevOps release gates with Azure Functions, PowerShell and VS Code
Additionally, you may consider to use quality gates with a work item query: Use approvals and gates to control your deployment

How do I retrieve my custom variables from a Bamboo Atlassian Build Plan via REST API

I have a bamboo plan that runs on every commit to a github pull request. In that bamboo plan there are a few custom variables on it such as Git Sha, Github Pull Request Number, etc.
I want to write a script that stops all previous builds (multiple concurrent builds) that have the same pull request number -- same custom variable value.
The reason for this is that if someone makes a quick change to their pull request (comments on the review, etc) that we don't have multiple builds running when only the last one is necessary.
I know it is possible to stop a build with a rest request, but I need a way to be able to get all running builds with custom variable value = 27 (pull request number). Once I know this, I can proceed.
At the time of writing, the REST API documentation doesn't list any method of querying the running builds for a particular build variable.
A solution would be to create your own plugin for Bamboo that exposes a REST service that does this query for you, but I don't know which of the Java APIs you would need to use in order to perform that query.
Here is how I solved this ...
You can call /rest/api/latest/result/<plankey>-latest?includeAllStates=true&expand=variables where plankey is the key for the specific Bamboo build plan.
You then loop through the results you get back, looking for a lifeCycleState value that is not Finished, and a custom variable with the desired name to see if it matches the PR number you have.

Jenkins Workflow API - stage status

What information are we able to query on a workflow job? Anything regarding a particular build's stage status (succeeded, failed, hasn't reached yet, aborted, etc.)? I see we can interact with the input step using this method, but where can we find what metadata, if anything, can be obtained about our builds?
The REST exported API for builds (…/job/…/…/api/json?tree=…) is not very extensive yet. You can get some information about nodes in the flow graph (steps, and some associated block nodes—the stuff you see in Workflow Steps). It is possible to extract some information about stages from that, albeit not easily. Much more is available from the Java API.