SFPowerscripts is an Azure Pipelines Extension that converts Azure Pipelines into a CI/CD platform for Salesforce. The extension features the following tasks
Please note this extension only works with the newer source format based repositories only.
- Authenticate a DevHub using JWT
- Authenticate a Sandbox using JWT
- Authenticate an Org using Username/Password/Security Token
- Create/Delete a Scratch Org
- Deploy a source format based repo to an org (scratch org/sandbox/prod)
- Create an unlocked package
- Deploy an unlocked package to an org
- Trigger Apex Test
- Validate Apex Test Coverge of an org
- Validate a Unlocked package for metadata coverage
- Install all package dependencies of an unlocked package
- Install SFDX along with SFPowerkit Plugin
- Increment Project Version Number similar to npm version patch, which can be utilized before an unlocked / source based packaging
- Create a build artifact for unlocked/source based packaging, which can be utilized in Release Pipelines
- Checkout a source based artifact from Git using PAT
What is it?
- The extension is designed with tasks which are granular, which means all the above tasks has to be orchestrated in a valid order required to reach the required objective. This allows one to utilise other commands or extensions between the tasks and be highly effective rather than getting tied to a single task. This ensures maximum flexiblity while building the pipeline.
For eg: a Pull Request validation for an unlocked package should feature the tasks in this order
- Install the SFDX CLI
- Validate the unlocked package for metadata coverage
- Authenticate DevHub
- Create a Scratch Org
- Install Package Dependencies in the target scratch org
- Deploy source to the target scratch org
- Delete the scratch org
Most of the tasks are very thin wrappers aroud the equivalent sfdx cli commands or the open source sfpowerkit (SFDX CLI extension). Almost all parameters that are requred during a CI run is exposed. If you feel that is not enough for the task at hand, one can quickly fall back to command line parameterized just for the task
Though the tasks can all be utilized fully in build pipeline. It is recommended to utilize the Release Pipeline to deploy the artifats to make the full use of Azure Pipelines Capability.
Why do I have to use this? Can't I script it out?
Of course you can, here are some advantages
- Save time from writing bash scripts in hooking all these tasks, such as ensuring you get the result values from the json output and parsing it to the next command
- Eliminate waste, multiple hours are spend on creating these scripts across multiple projects
- Open Source, so fork it and contribute it back
What if there is an issue with the plugin?
Please create an issue, and I will try to rectify as soon as possible. Wile it being fixed, you can omit the particular task from the extension and resort to command line using simple scripts
Sample orchestration pipelines are available in the Sample Pipelines Folder. Import these pipelines (in JSON Format) to your Azure Pipelines instance , set the variables and other parameters and you will be ready to utilize a highly customizable pipeline in the shortest time.
The following sample pipelines are available.
PR Pipeline using a Scratch Org
Unlocked Package Build Pipeline
Unlocked Package Deployment Pipeline
Source based Package (Org based Development) Packaging Pipeline
Source based Package (Org based Development) Deployment Pipeline