Fetch AzureDevops build details by Pull Request - azure-devops

My requirement is to tell the user if his/her PR got deployed successfully or not
So I thought,
I can ask user about his PR#
Using PR# - Fetch Build Details
Using BuildID from Step 2, find deployment information
I stuck at step 2
I am using below documentation to fetch build details.
https://learn.microsoft.com/en-us/rest/api/azure/devops/build/builds/list?view=azure-devops-rest-6.0
Not able to find correct usage of reasonFilter parameter to pass pull request id to fetch build details
API URL Info
Build Reson
Can someone help how exactly to use reasonFilter parameter here
tried this _apis/build/builds?api-version=5.1&$top=1&reasonFilter=pullrequest=20056

Regarding the point you're stuck with: The reasonFilter is simply a number of predefined string values you can choose from. For instance, if you specify reasonFilter=pullrequest, you get all builds started by a pull request. Thus, you can't specify the exact PR ID here.
Regarding your requirement in general: I don't think there's an API to strictly tie the PR ID and its build(s). You should look into the Status API instead. The build is just one of the statuses that can be associated with the pull request or, more specifically, with the commit.
So, I would approach your task the following way (note that it's not an exact algorithm, but a number of steps I would try to find the solution):
get the pull request by the PR ID provided by user
find the lastMergeCommit in the response
get the statuses of that merge commit
investigate the collection of GitStatus objects returned back and find out how to filter the build you're looking for (I don't know the format of that response for sure, but I'm confident there's some attribute to judge by)
Hope this can lead you to the right direction.

how exactly to use reasonFilter parameter here tried this _apis/build/builds?api-version=5.1&$top=1&reasonFilter=pullrequest=20056
Based on your requirement, you need to filter the build via build reason and Pull Request ID.
I'm afraid there is no out-of-box parameter to filter by pull request ID in the Rest API.
For a workaround, you can try to add the tag to your build.
Here are the steps:
You can add a step in your build to use Pull Request ID as Build tag. Refer to this doc: AddBuildTag: Add a tag to the build
For example:
- powershell: |
Write-Host "##vso[build.addbuildtag]$env:SYSTEM_PULLREQUEST_PULLREQUESTID"
displayName: 'PowerShell Script'
condition: eq(variables['Build.reason'], 'pullrequest')
You can set the condition to make sure that when the pipeline is triggered by pull request, it will add build tag.
You can add the tagFilters in Rest API to filter the related build.
For example:
Get https://dev.azure.com/org/project/_apis/build/builds?reasonFilter=pullrequest&tagFilters=PullrequestID&api-version=6.0

Related

Fetch the data from Power BI related to username/emailId by whom Azure Pipeline was ran

"https://analytics.dev.azure.com/{organization}/{project}/_odata/v3.0-preview/PipelineRuns?"
Using this url I am able to fetch RunNumber, RunReason but unable to fetch RunBy which user.
You could get the user that requested the run using predefined variables.
$(Build.RequestedFor)
And additionally you can also use
echo $(Build.RequestedForEmail)
echo $(Build.RequestedForId)
https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml#identity_values
There are some predefined variable for RunReason and BuildID as well.
$(Build.Reason)
$(Build.BuildId)
According to your description, I tried to get the odata feed "https://analytics.dev.azure.com/{organization}/{project}/_odata/v3.0-preview/PipelineRuns" in Power BI, currently there is no option to fetch who trigger the pipeline. And check the REST API is also without this.
You could use "Request a feature" on the left side of Developer Community to open a new suggestion ticket.
For more information about who trigger the pipeline, you could refer to this.

how to check any open pull request in GitHubs?

I got a coding challenge from a company and they require to complete a project on https://www.hatchways.io/
I already completed all of the code, but as I submit it shows that
{ Before you submit the Front-end Work Simulation - Hatchways Times project, you will need to pass the following pre-checks:
You must have an open pull request. ❌
You do not have multiple pull requests opened. ✅
Sorry, looks like you didn't pass all the pre-checks above. Please make sure you satisfy all the requirements before you retry. }
I have two branches one is 'main' another one is 'practice'. I already checked I don't have any pull request both of branches.
Is there anyone know how to solve it please?
Pull Request
record of pull request
Click New pull request
Set the branch to practice and the base branch to main
Submit

Is there a way to get the amount of lines changed in a Pull Request via the Dev Ops Service REST API?

I am currently doing my thesis and analyzing the behavior for code reviews. For this I want to know the size of the pull request that is reviewed. The rest of the information for example authors, reviewers, times etc. I got already by calling the rest API. However I cannot seem to find a way to get the amount of lines changed in each file, or a total number (which is also sufficient).
I have browsed the documentation and found some ways to get amount of files changed, see https://learn.microsoft.com/en-us/rest/api/azure/devops/git/commits/get%20commits?view=azure-devops-rest-5.1. However, I didn't found a way to get the amount of changed lines per file or a total amount.
So is there a way to get amount of lines changed in a Pull Request or between two commits?
For your issue , I am afraid that there is currently no official released REST API to do that. A similar question has been answered in this case ,please refer to it for details, you can refer to these steps to achieve your requirements:
1.Get a list of commits to get a commit’s commit id.
2.Get a commit by commit id (steps 1) to get parents value and repository id (The value at the end of _links>Repository>href) (Using the URL of _links>Changes>href can get file path if you don’t know)
3.Get file diff by this POST request https://dev.azure.com/{organization}/{project}/ _api/_versioncontrol/fileDiff?__v=5&diffParameters=[data 1]&repositoryId=[repository id]
You could also add your request for this feature on our UserVoice site, which is our main forum for product suggestions,our PM and product team will kindly review your suggestion.

How to get the associated changes, check-in comments and linked work items for a particular build/release in VSTS

I am using SendGrid email extension to trigger a custom email notification after the CI/CD process is complete in VSTS. This email task has HTML content in it which includes some content fetched using standard build/release variables (https://learn.microsoft.com/en-us/vsts/build-release/concepts/definitions/build/variables?tabs=batch).
How do I include associated code changes, check-in comments and linked work items for a particular release in the custom email? Are there any variables I can use? Any work around?
There aren’t the built-in variables that can get code changes, check-in comments and linked work items.
You can get them through REST API during build or release:
Get build changes and work items through Get Build Changes REST API (Build id variable: Build.BuildId during build or Release.Artifacts.{Artifact alias}.BuildId during release) Note: using Build.SourceVersion to get latest version)
Git: Get commit message through Get a batch of commits by a list of commit IDs REST API
TFVC: Get check-in comment through Get list of changesets by a list of IDS REST API
To get changed items, you can use get commit with changed items or Get list of changes in a changeset REST API.
No API to get detail code changes, but you may refer to this related issue: Lines of Code modified in each Commit in TFS rest api. How do i get?
Assuming TFS (which isn't specified in the question or tags), you could also call tf.exe directly to get some of that info. If you don't care about the output format, then the output of the following command produces a report of the Changeset details.
tf vc changeset <changeset id> /loginType:OAuth /login:.,<token> /noprompt
Where <changeset id> is the numeric Build.SourceVersion, and <token> is the System.AccessToken.
Comments and source code edits listing are included in the report.
Note: the agent job has to be given the "Allow scripts to access the OAuth token" permission (check box on the Agent Job properties).
See the updated link below for details on how to access the build variables. Same content as in the question, but new link. Both currently work.
https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml

how to get all the Task in a Workitem in Json form by postman for TFS API

i am currently using TFS API who's link is
https://www.visualstudio.com/en-us/docs/integrate/api/wit/work-items#byids
currently in my project i want to accees the following workitem 61092 all the task
http://apactfs.cbre.com:8080/tfs/CBRE.APAC.Applications/MRI_SCRUM_GIT/_workitems?_a=edit&id=61092
for that i am using this link in postman GET
http://apactfs.cbre.com:8080/tfs/cbre.apac.applications/_apis/wit/workitems/61092?$expand=all&api-version=1.0
i am getting all the task related to it but not getting all the field such as number of hours in the task,user of the task which i wanted.
and in Postman i am hitting the id by this Link By GET
http://apactfs.cbre.com:8080/tfs/cbre.apac.applications/MRI_SCRUM_GIT/_workitems?_a=edit&id=61092&api-version=1.0
According to your screenshot, 61092 is a Product Backlog Item. The Rest API URL you use can only get the detailed information of the work item 61092 itself, it cannot get the detailed information about the work items that linked to 61092.
You have to use One-hop Query to get all the tasks related to it and then get the detailed data for each task returned. Refer to this link for details: Get Work Items.
$expand=all has already expand all fields, but it doesn't show the empty fields in response. If you type a value for the field you want to get, you will see it as expect in response.