Azure Pipelines DevOps Not Being Triggered by PR - azure

I've been using Azure Pipelines for a while now and haven't changed my azure-pipelines.yml file here in 2 months. Previously, when there was a new PR, the pipeline would trigger and cause the environment to be built and the tests would be run.
Today, there was a new PR but I noticed that the pipeline was not being triggered. Then, to further test this, I forked, cloned, and branched the repository myself and created another new PR and, again, the pipeline was not triggered.
It's not clear to me where things are getting stuck and it's not clear how one would debug this. I've gone through this Azure DevOps documentation but it wasn't useful. I can manually trigger the pipeline to execute and test the master branch but I don't know how to manually trigger the same thing for a PR. Here's my Azure DevOps page for reference.

As normal, you do not need config pr in YAML script if there's no any special demand, we would do pull request trigger for all branches. But, it start broken from 03-13 21:02 (UTC), which caused by us, you do not do anything wrong.
The fix is preparing with our best.
As Alex said, this is the implicit trigger which YAML support only, if you do not configure pr in YAML explicitly.
To avoid such stuck later, except the method that Alex mentioned: add pr into YAML. You can also make use of UI configuration which performance is very stable until now.
Just go Pipeline definition page => Click on three dots of right corner => Select Trigger:
Then you will see Triggers tab which has Continues integration and Pull request validation display below. Open Pull request validation and enable Override the YAML pull request trigger from here:
Additional, Our team has noticed this broken issue, will update whether it is fixed here once we have any fixed release in progress.
Update 3/18/2020:
Fixed has released to all region. Every one can work github pr trigger as the document shows now.

Related

Unable to queue build error with Azure DevOps Pull Request

I want to trigger a build before pull request starts for merging (in Azure DevOps). For this option, I have added the Build validation under branch policies. But if I created a new Pull Request, I am getting the message as "Unable to queue build".
Please anyone let me know the option I selected solves my requirement. If yes, how to solve this "Unable to queue build" issue. If no, any option available to achieve my requirement.
Thanks
Your options is achievable, and the problem now is most likely caused by you triggering the pipeline in the wrong repository.
For example, if you create a pipeline from repository 1 and trigger the pipeline in a pull request created from repository 2, the pipeline will not be queued.
Modify your pipeline or PR repository so that the pipeline and PR use the same repository, this should be resolved.
I had the same problem and i changed the branch policy to include the build pipeline:
https://learn.microsoft.com/en-us/azure/devops/repos/git/branch-policies?view=azure-devops&tabs=browser
Branch policy could be found from:
Repos -> Branches
Click on the 3 dots to the right of the branch that the PR is going to.
I was also facing the same problem, checking pipeline for being disabled or edited anyhow, but no differences.
But by checking the linked work items (tasks/pbis), I saw that one or more had not been completed. After changing the states everything worked fine.

Trigger Azure Pipeline on Merge

I have a use case where I have two pipelines configured. One for running tests which are triggered by a Pull Request and another pipeline that is handling deployment. I am using Bitbucket cloud in Azure.
Pipeline A - Run through tests on PR.
Pipeline B - Deploy upon successful merge (approved pull request).
My current setup is to trigger pipeline A when a pull request is submitted. This is no problem and works as intended. The issue I am running into is with Pipeline B. It is triggered regardless of whether the PR is approved or even merged. I know that expected behavior for the CI trigger is to fire off with any action on the branch. The PR trigger also doesn't fit my needs though as it would be redundant with Pipeline A.
What I would like to happen is since Pipeline A fires off on PR, a code reviewer will Approve and Merge the PR and only if the PR ends up getting merged into the Release branch is Pipeline B triggered. Is this possible?
Developer completes code.
Developer submits PR against a Release1.0 branch.
Pipeline A triggers. Tests pass or fail.
Code reviewer approves and merges PR into Release1.0 branch.
Pipeline B triggers and deploys.
UPDATE: For those who bump into the same issue it's actually quite a simple fix. Simply setting the trigger...
pr: none
in Pipeline B will do the trick.
To be clear, this solution is specific to Bitbucket Cloud and GitHub repositories only. The 'pr' syntax in YAML pipelines doesn't exist for Azure Repositories (use branch policy instead).

How does a PR pipeline vary from CI pipeline in Azure Devops?

I know this is a basic question but can someone explain with a scenario based on VCS like Git
A "PR" pipeline is just a pipeline that is triggered by a new pull request. It will usually run tests, static analysis, linting, or other checks against the incoming branch as a way to ensure coding standards are met before merging the PR. Azure DevOps will show the progress and result of the build on the PR page as well.
A CI pipeline is usually triggered when a specific branch is changed (perhaps master or develop). A build is automatically kicked off to run build/tests/static analysis/archiving/etc to ensure the new commits do not break things.
Here is more information from Microsoft that may help:
https://learn.microsoft.com/en-us/azure/devops/learn/what-is-continuous-integration
Hope this helps!

What is the difference between Continuous deployment trigger and Pull request trigger?

Azure DevOps Release pipeline artifact settings has 2 options:
Continuous deployment trigger - Enabling the trigger will create a new release every time a new build is available.
Pull request trigger - Enabling this will create a release every time a selected artifact is available as part of a pull request workflow
I am trying to understand what is the difference between these options with respect to the highlighted parts and whether the build validation policy causes release to trigger with both options, if so then why do we have pull request trigger?
In my opinion, these two triggers have different working scope.
Assuming we set one CI build as release artifact, according to my test:
1.Continuous deployment trigger:
Whenever we have a new version of the Build, it triggers the release. It means that no matter the build pipeline is triggered by manual run, CI trigger or build validation in branch policy, the release is triggered when there's one newer build.
2.Pull request trigger:
It has a smaller scope, it will be trigger by the build pipeline which is trigger by build validation in branch policy.
(Which is triggered by PR, so if we create new PR=>It triggers PR build=>It triggers PR release)
Feel free to correct me if I misunderstand anything.
Update1:
Here's one pic about my two tests:
Release-8 is triggered by my manual running Build pipeline with only CD triggered enabled. And Release-7 is triggered by PR build with only PR triggered enabled. (I only enable the Pull Request for deployment in Stage 1)
Apart from working scope, these two triggers also have a little difference here. The Pull Request Deployment in stage for now is only for PR trigger in Artifact.
This explains that very well (taken from documentation):
Pull requests (PRs) provide an effective way to have code reviewed
before it is merged to the codebase. However, certain issues can be
tricky to find until the code is built and deployed to an environment.
Before the introduction of pull request release triggers, when a PR
was raised, you could trigger a build, but not a deployment. Pull
request triggers enable you to create pull request releases that
deploy your PR code or PR builds to detect deployment issues before
the code changes are merged. You can use pull request triggers with
code hosted on Azure Repos or GitHub.
New build basically means that your pipeline was executed.
Creating pull request trigger you need to define an artifact which will be later deployed. For this kind of trigger Azure Devops runs your pipeline and produce artifact according to your pipeline/build definition and later use this artifact for deployment.
Both trigger are similar, the difference is when your code will be deployed before or after being merged into main branch.
PR trigger is part of CI - applies when your merge your branch to master
CD trigger - applies only to the master branch

Azure DevOps Pipeline build triggering unexpectedly

Updated 26-Feb-2020
In our Project, I have a pipeline "MyPipeline" which restores the NuGet packages, builds the solutions and runs the tests.
On the master branch, I have a policy which does things like add code reviewers, and it has a "build validation" step which executes "MyPipeline". All well and good.
However, I created another branch from Master called NewBranch and synced (pushed) this up to Azure. After doing some minor changes in Visual Studio, I did a merge from master, committed and sync'd to Azure.
I was a bit surprised then to see "MyPipeline" executing. It seems to have been triggered when I pushed my changes to NewBranch to Azure. I don't have a branch policy on "NewBranch". The trigger in the YAML file is:
trigger:
- master
What kicked this off? I'll soon burn through my free agent minutes if this continues...
Update 26-Feb-2020
As per the comments below:
The history of commits on the master branch are:
Tue 9:10 PM
Tue 7:47 PM
Mon 2:46 PM
The history of the pipeline execution show:
Wed 9:14 AM "PR Automated"
So, nothing new has been committed to the Master branch. However, I think I know what's causing this. Just that I'm not convinced on the timing....
So, we have two branches, master and NewBranch.
Master has a policy that requires two code reviewers to Approve, and it requires the build to succeed. Because of this policy, a developer can't therefore merge directly into master - they have to generate a Pull Request.
So, Developer A creates a Pull Request to merge NewBranch to Master. There is then the rather lengthy code review process which may take multiple additional commits to the "NewBranch"'s Pull Request before it's deemed acceptable.
What seems to be happening is that everytime one of these new Commits is sync'd to the Pull Request, a build is triggered. Is this a good thing? Maybe, Maybe not. If the build is going to trigger just once, then the compilation should occur when all the code in the Pull Request has been approved, not before hand. Why trigger a build at such an early stage; the master branch may be updated by multiple other Pull Requests before this is ready to be merged in. However, with unlimited resources, then I guess there's no harm in building as often as possible, but a) this can delay other builds (representing an impediment to other developers) and b) this uses up the free limit on agent time.
The detailed info you share in question is much help for me to understand the whole workflow of yours.
Though you did not express too clear, but, yeah, what you are guessing is correct. The action you faced is expected and by designed. The root cause is you are using branch policy and the Build validation also included into this policy.
The nutshell is you are using Pull request trigger.
Explanation:
Let's pay attention to its definition:
Pull request (PR) triggers cause a build to run whenever a pull request is opened with one of the specified target branches, or when
changes are pushed to such a pull request.
Based on your added contents, your developers are pushing changes (new commit) into the opening Pull request (Note: The key point is Pull request is still be opening.) This belongs to the work scope of the PR trigger because of above definition. That is why the build triggered every y new changes pushed into NewBranch branch.
Work around:
I agree with the logic of #devpro's answer. But its script does not available for your scenario. Because the pr in YAML only work for GitHub and Bitbucket Cloud repos.
Here you are using VSTS repo, and configured the policy for it. So, you can only via branch policy configuration to avoid such burning trouble.
In your Build validation panel, you are setting build policy with Automatic, right?
Please change the Automatic to Manual, also keep the Policy requirement value as Required.
Now, the corresponding build pipeline will not be ran automatically once new commit pushed, it can only built when someone run it manually.
For the delay timing you noticed which make you unsure, I guess it would because of conflict.
For sample, the Pull request P1 which merge from NewBranch to Master is opening. I commit a new change C1 into NewBranch. BUT, it causes the conflict. At this time, the build will not be ran because the changes does not actually pushed into PR.
Note: The commit is true to NewBranch. BUT changes does not accepted by PR yet, because PR detect out there has conflict here and you must tell PR which changes you want to keep. Only the changes pushed into PR can work with PR trigger.
Only the conflict solved, the changes, maybe I can say commit, can truly be accepted and pushed into PR. Then the triggered build ran.
This would be the time period delay you noticed.
I've seen the same behaviour today.
Can you try rewriting the trigger part in your pipeline like this:
trigger:
branches:
include:
- master
Does that help ? I can't verify it myself yet, since I've done that change but the PullRequest isn't approved yet :)
I've also another repository where I do not see that behaviour, but there, my pipeline trigger looks like this:
trigger:
- master
(Notice the 2 spaces before - master)
I think you need to add pr: none to your pipeline definition to disable the automated run.
If pr is not set I think the default is to run on every PR.
That would give something like this:
trigger:
batch: true
branches:
include:
- master
paths:
exclude:
- README.md
pr: none

Resources