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.
This pipeline is triggered on every pull request raised against a develop/master branch depending on your git flow.
You can import and modify this pipeline using the file provide in the link
The steps that are part of this pipeline are (in the exact order)
- Install SFDX CLI
- 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)
- Trigger Apex Tests in the scratch org
- Validate the apex test coverage in the org
- Create/Delete a scratch org(Action :Delete) (Optional : Depending on the maintain org option used in step 4)
This pipeline need to be enabled only with PR triggers, CI triggers for pipeline should be disabled. Follow this documentation to enable this PR trigger using this link