Audit logs if someone execute/ rerun failed job in Azure DevOps Pipeline - azure-devops

How do i know who executed or rerun the failed jobs in Azure devops pipeline which ws initially triggered by x user.

If you want to get Azure Pipeline build result, you can use the following rest API
GET https://dev.azure.com/{organization}/{project}/_apis/build/builds?definitions={definitions}&queues={queues}&buildNumber={buildNumber}&minTime={minTime}&maxTime={maxTime}&requestedFor={requestedFor}&reasonFilter={reasonFilter}&statusFilter={statusFilter}&resultFilter={resultFilter}&tagFilters={tagFilters}&properties={properties}&$top={$top}&continuationToken={continuationToken}&maxBuildsPerDefinition={maxBuildsPerDefinition}&deletedFilter={deletedFilter}&queryOrder={queryOrder}&branchName={branchName}&buildIds={buildIds}&repositoryId={repositoryId}&repositoryType={repositoryType}&api-version=6.0
For more details, please refer to https://learn.microsoft.com/en-us/rest/api/azure/devops/build/builds/list?view=azure-devops-rest-6.0

Related

Azure DevOps ServiceHooks: Run Job state changed webhook

I am trying to use the service hook of azure devops, and while applying the the filter “Run Job state changed webhook”.
The pipeline running contains 8 jobs and when their states change none of them triggers the webhook and there is no attempt in the history of the pipeline. However when trying to test the service hook using the “Test” button, the attempt succeeds and the request is received normally.
Any ideas what might be the root cause of the problem and how to fix it?
Thanks in advance

Get Azure Devops Pipeline Step Runtimes

Looking through the Azure Devops APIs it appears like it isn't possible to get the runtime of individual steps in a pipeline run?
Pipeline steps
I'm looking to scrap the runtime of each step in a pipeline run across all runs of a pipeline.
I've looked at the Azure Devops APIs, and while I see how to get pipeline run details here, it doesn't appear like the API includes step level information.
You can use Timeline - Get REST API to achieve the runtime of individual steps in a pipeline run. Please refer to doc:Timeline-GET-REST APT
For example:
URL
GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/timeline/{timelineId}?api-version=5.1
Test in postman:
The response body returns a list of build details that include job/step/task type and name and startTime and finishTime according timeline.

Is it possible to send Azure DevOps service hook-webhook to log analytics custom table

What I want to do is to generate Azure monitor alerts for Azure DevOps pipeline failures.
We think we may achieve this without having to modify our DevOps YAML pipelines. So we focused on using Azure DevOps Service Hooks to do this by sending the pipeline log data to the log analytics http data API.
I can send the data with Powershell. However I got a forbidden failure when testing the service webhook in Azure DevOps.
So I wonder if there is any missing operations?
enter image description here

Querying the agent a build step was run on from Azure DevOps via REST API

I need to extract information from a finished pipeline build in Azure DevOps. I can get the tree of steps in the executed plan for that build and the attached logs. The final piece of information that I'm looking for is the name of the build agent that was used to execute a certain step. How can I query the agent? The web frontend clearly shows the info, but I don't see it exposed via the documented API.
Querying the agent a build step was run on from Azure DevOps via REST API
First, there are Use predefined variables, which provide a list of predefined variables. You could use the Agent.Name to get the name of the build agent.
If you want to use REST API to get the name of it, you could use the REST API Builds - Get Build Log:
GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/logs/{logId}?api-version=6.0
Then we need to parse the log to get the name of the agent:

In Azure Devops I want my yaml pipeline only to execute after the previous execution of the same pipeline has completed

I tried batch: true setting described here, but it seems to:
ignore commits that are pushed when a pipeline is running. I want the last commit to trigger a pipeline after the current run of that pipeline has finished
be ignored when you publish directly from CI by pressing build
Has someone found a way to configure a pipeline to run as I have described.
You can try adding a Invoke REST API check on the agent pool. The rest api will get the previous build and evaluate its status. So when new build is queued targeting the agent pool. The Invoke REST API will be invoked, this new build will only start when the response of the rest api is evaluated to true.
Please check below steps:
1, create a service connection to your azure devops organization.
Go Project Setting--> Service connections under Pipelines-->Click new service connection--> select Generic to create a generic service connection.
Then Edit the service connection type the information shown in below screenshot. Check here to get a Personal access token.
2, add Invoke REST API check on the agent pool**.
Go Project Setting--> Agent Pools under Pipelines-->Select the agent pool--> Click the 3dots -->Click Approvals and checks.
.
3, Click the "+"--> Choose Invoke REST API
4, Edit the Invokde Rest API
Select the generic service connection to your azure devops created in the first step.
Set the fields as below:
URL suffix and parameters: _apis/build/builds?definitions=the DefinitionId of your pipeline&$top=2&queryOrder=queueTimeDescending&api-version=5.1
Success criteria: eq(root['value'][1]['status'], 'completed')
please check here for more information about build rest api.
Note: Since the Invoke Rest api check is set on agent pool scope. It may have effects on other pipelines that target this agent pool. For example, if the desired yaml pipeline is waiting its previous run to complete. And now another pipeline targeting this same agent pool is triggered, it will have to wait for the previous run of desired yaml pipeline to complete too.