Run azure pipeline on PR to the main branch

Has anyone figured out the way to run azure pipeline on pr to the main branch ? Looking for pattern and any reference solutions folks have already figured out or ideas to achieve it. Our intent is to create infra using terraform on pr with pr-sha which will be available for developers to review on the pr and merge to main with confidence. Thinking of pr- preview environment (ephemeral) for developers. Any thoughts/ref solutions are welcome.

On the branch policy, you would add a Build Validation step that uses the particular pipeline.

I don’t believe Azure DevOps supports this trigger in the YAML file.

  • Thank you for this and do you have any ref link or examples you can share ?