This pipeline demonstrates how you can build a pull request validation pipeline using scratch org. Here is a snapshot of the steps we have used to configure a pipeline. The intend of this pipeline is to validate a pull/merge request into the integration branch upon completion of a feature branch by developers.
The pipeline demonstrated below is a quite simple one, assuming there is only one package directory in your project. If you are having a mono repo with multiple package directories, the PR validation Job will feature multiple deploy tasks
This pipeline is triggered on every pull request raised against a develop/master branch depending on your git flow.
The pipeline is available as part of the sample pipelines.
The steps that are part of this pipeline are (in the exact order)
Validate Unlocked Package ( Only necessary if you are building an unlocked package)
Authenticate an Org( In this case, it is authenticating against DevHub)
Create/Delete a scratch org( Action :Create)
Deploy source to scratch org ( Deploy)