azure-devopsazure-repos

How to get PR title and description from agents


Is it possible to get PR title and PR description in pipeline?

The idea is to notify team which task has been deployed. Allfeature need to be tested go to branch "development" I tried intergrate Ms Teams, subscribe pipeline, but none of the information is useful.

Build pipeline gave me branch "development" which is not helpful (not sure what was merged into "development") and who was requested the build

Deploy pipeline gave absolutely nothing useful.

Update:

The Picture below is result of querying Builds - Get Api. Trigger for a PR was completed. There is no infomation about the PR. enter image description here


Solution

  • If your build is based on pull request commit , the sourceVersion will be displayed next to the source branch in the build summary page.

    Click on this sourceVersion, you will jump to the detailed page containing pr title and description, in this page you can also see the merged changes.

    enter image description here

    enter image description here

    Update:

    or a way to query PR title in build or release process

    How about getting pr title through rest api? We can first use Builds-Get rest api to get the pull request id in the specified build.

    GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}?api-version=5.1
    

    enter image description here

    enter image description here

    Then through the obtained pull request id, we can use Get Pull Request rest api to get the pull request title.

    GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullrequests/{pullRequestId}?api-version=5.1
    

    enter image description here

    The above can be achieved by adding a powershell task(call rest api through script) in the build or release process.

    Update2:

    The difference between PR-triggered build and CI-triggered build:

    enter image description here

    If the build is triggered by pr, the trigger reason should be pullRequest. Below is my test in Postman:

    enter image description here