This pipeline demonstrates how you can build a continous integration pipeline for an unlocked package. This pipeline is triggered on every successful completion of a feature branch into the develop/master branch. If the frequency is quite high, you can look into utilizing [ci skip] in front of the commit message to skip a trigger of this pipeline
The pipeline demonstrated below is a quite a 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 create version tasks. You can also have source packages along with unlocked packages in the same project directory
Here is a snapshot of the steps we have used to configure a pipeline.
jobs:- job: Build an Unlocked PackagedisplayName: Unlocked Package build for <MyPackage>condition: and(eq(variables[\'build.sourceBranch\'], \'refs/heads/master\'), ne(variables[\'build.Reason\'], \'PullRequest\') )steps:displayName: Install SFDXdisplayName: Authenticate Orginputs:method: 'ServiceConnection'salesforce_connection: '$(service_connection)'alias: 'DevHub'displayName: Create a new version of Packageinputs:package: <MyPackage>tag: <Mytag>config_file_path: 'config/project-scratch-def.json'installationkeybypass: trueenable_coverage: falseisValidationToBeSkipped: falsedevhub_alias: 'DevHub'wait_time: '120'build_artifact_enabled: true
The steps that are part of this pipeline are (in the exact order)
Authenticate an Org( In this case, it is authenticating against DevHub)
This pipeline need to be enabled only with CI triggers, PR triggers for pipeline should be disabled. Follow this documentation to enable this CI trigger using this link