Linked work items not available in Pull Request CI build in Azure Devops - azure-devops

I have a CI build set up in Devops that runs with every Pull Request submitted for our master branch, and then also on a daily schedule whenever our master branch has been updated (after successful review).
When I look at the pipeline history, the builds that ran for PR's have no linked Work Items (even though items were linked in the Pull Request).
Only the builds that run AFTER the PR has completed and merged into master (ie the ones that run against master, not the PR branch) have the items from the Pull Request linked.
Is it possible to link work items from the PR to the PR build or at least access them from the CI pipeline?
I'd like to add a task to my CI pipeline that automatically updates all Work Items linked to a PR to "In Code Review" status when the CI build for the Pull Request starts, but the items are only available in the post-PR builds.

If you want to display the linked work items on the summary page of the build triggered by the pull request, you need to add the linked work items on the Commit page.
The linked work items added in the pull request page will not be displayed on the build summary page.
Currently, this is by design. If we want to get the work items from the pull request link to the build, we can get them through rest api, but they will not be displayed in the build summary.
GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/workitems?api-version=6.0
Here is a ticket with similar issue you can refer to.

Related

How to limit associated work items in Azure DevOps YAML pipeline once PR is merged?

I've been migrating build/release pipelines in Azure DevOps to the unified YAML format. Everything works as expected apart from the work items which are associated with CI builds once a PR is merged to the master branch. Here is the workflow:
Developer raises PR to merge changes from feature branch into the master branch
The PR has a build policy which executes the YAML pipeline against a test environment
The PR is completed and the feature branch is merged into the master branch
The YAML pipeline has a CI trigger for deployments to higher environments
For step 2 the triggered build shows whichever work items are associated with the PR:
However, for Step 4 the triggered CI build lists all work items in the master branch rather than just those associated with the PR:
Is there a way to only associate the work items which are associated with the PR to the CI build which is triggered once the feature branch is merged into master?
I can reproduce this issue and I found a similar ticket, they have reported it, you could follow this ticket to get the latest news.
If the build status is queue or running, then we create a new build, the new build will contain before build link work item. This is why the step 4 the triggered CI build lists all work items in the master branch rather than just those associated with the PR.
If all builds are completed, then we complete the pull request to trigger the CI build, it will be associated with the expected work items.
When all the builds were completed, I merged the PR to trigger the CI build, it just contain the pull request link work item.
Test result

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.
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.
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
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
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:
If the build is triggered by pr, the trigger reason should be pullRequest. Below is my test in Postman:

Triggering Pull Request Builds automatically on draft pull requests in Azure DevOps (ADO)

If I make a pull request in ADO from one of my branches then any commits I push to my branch automatically trigger the build pipeline:
This is configured in the build validation branch policies on master:
But for draft pull requests I need to trigger builds manually:
The documentation (here) does not mention any distinction between active and draft pull requests. How do I configure my project so that commits to branches in a draft pull requests automatically trigger a build?
According to the docs:
Draft pull requests do not include reviewers or run builds by default
but allow you to manually add reviewers and run builds. To promote the
pull request to a normal pull request, simply click the Publish button
from the pull request detail page.
So, it looks like you experience the expected behavior.

Triggering Jenkins Multibranch pipeline when there is a pull request created in GitHub

I'm using Jenkins Multibranch pipeline. I've configured the APIs(github-webhook and ghprbhook) in GitHub. I want to trigger the Multibranch Pipeline whenever there is a Pull Request on GitHub (without using periodical option).
For example, if i create pull request on GitHub, then the Jenkins Multibranch pipeline should start scanning and build the Jenkinsfile automatically.
What do i need to do to achieve this?
I would love to try if there are any suggestions.
Under the webhook section, you can choose Let me select individual events option. Under that you can have push selected by default and also can select Pull Request which helps you to do wnat you are looking for Pull request opened, closed, reopened, edited, assigned, unassigned, review requested, review request removed, labeled, unlabeled, or synchronized.
To achieve this, I have selected "Send me everything" under GitHub Webhooks section.
Then I was able to trigger builds automatically whenever a PR is raised on GitHub.
As #RSharma mentioned, I have selected only "Push and Pull Request" under "Let me select individual events" section.
PS: The GitHub branches are automatically detected in Jenkins.

Showing Jenkins pipeline status against pull requests in GitHub

I have recently started using Jenkins Pipelines and have a multibranch job configured which is happily picking up Jenkinsfile on one of my branches.
I have seen in screenshots on posts\articles that Jenkins can report back to pull requests in GitHub the status of whether the branch has passed\failed checks performed in the pipeline.
I am not seeing any such feedback for my pull request I have opened, I can see in Jenkins it has triggered a pipeline build which has passed.
How can I get the notification to show the pipeline checks have passed in GitHub. Do I need to configure something else?
I found out this was simply down to me using the Git instead of GitHub sources option when configuring the multibranch pipeline job in Jenkins.
The docs for the GitHub Branch Source plugin gave me the clues!
I now get status messages on my pull requests showing whether pipeline checks are pending\failed\passed.
Check out the Github Pull Request Builder Plugin, it should do what you require: https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin