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

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.

Related

Can I trigger pipelines in other repos when I create a PR?

We have 3 repos in Azure DevOps. We use Azure Pipelines to run our CI/CD chain.
Repo A is a toolset used by the other repos.
Repo B uses A as submodule, and C uses A as git submodule.
When creating a PR in repo A, we want to trigger test Pipelines in repo B and C and have the status in repo A's PR. B and C's pipelines/runs should use the PR commit when running their tests. This to avoid that changes in repo A breaks repo B and C upon release.
Our problem is that we want to make sure to use the right commit of repo A (the one in the PR) and to get the test results for repo B and C in to the PR.
This should be possible through build-validation policies in a branch policy, but it won't be straight forward.
Under the hood, when you specify a build in the build-validation policy, azure-devops will queue the pipeline on a temporary branch /refs/pull/<id>/merge. It queues the pipeline with several additional variables that represent pull request meta-data. When that build completes, it sends a status message back to pull-request to indicate whether the conditions were met.
Microsoft has a few articles on how to create a custom PR server or using a Function App to create custom branch policies. These could be used as an approach, but both articles suggest that they invoke based on a webhook when the pull request is created. Both articles mention how to send custom PR Status messages back to the PR.
If you want more control over manually re-queueing the build-validation, you could in theory also create a pipeline that triggers the other pipelines in the other repos.
Define a build-validation pipeline that can be used to trigger the other pipelines. This is equivalent to using a Webhook/Function app, but the main difference is the UI in the Pull Request provides options to retrigger the build.
This build-validation pipeline reads the queue-time variables to identify which PR is being executed. You can add logic to this pipeline to use the Azure DevOps REST API to queue the pipelines in the other repos/projects. When queuing these pipelines, pass the details of the pull request meta-data as queue-time variables in the body of the message.
When the external pipeline runs, read the queue time parameters to record which PR initiated the build. Add some custom logic to include checking out the /refs/pull/<id>/merge branch for your submodules then Build + Test.
When the external pipeline completes, post the PR Status back to the originating PR.
Modify the branch policy to indicate the Build Status from the other pipelines as Required.

Azure Devops GIthub webhooks

We had azure pipeline which use to work, but recently the PR trigger are not working.
Hence, I deleted webhooks from github repo. I created new service account and new pipeline with new service account. However, it does not seem to recreate webooks in github.
any thoughts?
Which model are you using, classic editor build or YAML build?
If you are using YAML build, we could select GitHub as source.
And we could specify the target branches when validating your pull requests. For example, to validate pull requests that target master and releases/*, you can use the following pr trigger.
pr:
- master
- releases/*
If you are using classic editor build. We could select the Pull request validation trigger and check the Enable pull request validation check box to enable builds on pull requests. Check the pic below.
We could refer to this doc for more details.

Linked work items not available in Pull Request CI build in 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.

Triggering Jenkins Multibranch Pipeline automatically if a PR is raised on GitHub

I am using Jenkins Multibranch pipeline.
I've configured the APIs (github-webhook and ghprbhook) on GitHub.
Currently, If I click on "Scan Repository Now/Scan Repository Log" in Jenkins, the Jenkins will go through the GitHub and creates a new PR job in Jenkins if there are any PR on GitHub.
So I need to trigger this Multibranch pipeline whenever there is a Pull Request raised on GitHub. I want this pipeline to trigger automatically when there is a PR on GitHub.
What do I need to do to achieve this approach?
Is it possible to trigger Multibranch pipeline automatically whenever a PR is raised on GitHub?
To achieve this, I have selected only "Push and Pull Request" under "Let me select individual events" section of GitHub Webhooks.
PS: The GitHub branches are automatically detected in Jenkins.
Du you use the GitHub pull request builder plugin?
This Jenkins plugin builds pull requests from GitHub and will report the results directly to the pull request via the GitHub Commit Status API
When a new pull request is opened in the project and the author of the pull request isn't whitelisted, builder will ask Can one of the admins verify this patch?. One of the admins can comment ok to test to accept this pull request for testing, test this please for one time test run and add to whitelist to add the author to the whitelist.
If an author of a pull request is whitelisted, adding a new pull request or new commit to an existing pull request will start a new build.
A new build can also be started with a comment: retest this please.

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