Sub topic 15
Working with the Salesforce CLI
This chapter assumes you know how a DevOps Center pipeline moves work items through stages. It also assumes you have used Git branches and the sf command. DevOps Center handles the standard flow. The Salesforce CLI covers checks and edits that the DevOps Center interface does not offer.
Why use the CLI next to DevOps Center
DevOps Center commits to a Git repository. That repository is an ordinary Salesforce DX project, so any developer can clone it and run sf commands against it. The CLI is useful in three situations:
- You want to check a change against a stage's org before promoting it.
- You need to edit files that point-and-click tracking does not capture.
- You want to see exactly what a promotion would carry.
The project layout the CLI expects
The CLI reads sfdx-project.json to find your source directory.
{
"packageDirectories": [
{ "path": "force-app", "default": true }
],
"namespace": "",
"sfdcLoginUrl": "https://login.salesforce.com",
"sourceApiVersion": "62.0"
}A .forceignore file keeps local tooling files out of deployments, so only real metadata travels through the pipeline.
# .forceignore
**/jsconfig.json
**/.eslintrc.json
**/__tests__/**
.sfdx
.sfValidating a change outside DevOps Center
A validation-only deployment checks a change without saving it to the org. Log in to the stage's org, then run a dry run with local tests.
sf org login web --alias uat
sf project deploy start --source-dir force-app --target-org uat --dry-run --test-level RunLocalTests--dry-run makes the deployment validate only. RunLocalTests runs every test in your org except those from installed managed packages. The command reports component errors and test failures before you promote anything.
Seeing what a promotion would carry
Each pipeline stage maps to a Git branch. Comparing two branches lists the commits that have reached one stage but not the next.
git fetch origin
git log --oneline origin/main..origin/UATThe output lists commits on UAT that are not yet on main. Those are the changes the next promotion would carry.
Common errors
- Committing outside the work item branch. DevOps Center tracks each work item through its own branch. If you push commits to a different branch, the work item will not show them.
- Validating against the wrong org. Check the
--target-orgalias. A dry run against the wrong sandbox gives results that do not match the stage. - Skipping
git fetch. Without it,origin/main..origin/UATcompares stale data. - Treating a dry run as a deployment. It saves nothing, so the org stays unchanged.
Exercise
You want to know which commits would move from UAT to main in the next promotion, and you want to confirm the change deploys cleanly to UAT first. Which two commands do you use?
Show answer
Run git fetch origin followed by git log --oneline origin/main..origin/UAT to list the commits. Run sf project deploy start --source-dir force-app --target-org uat --dry-run --test-level RunLocalTests to validate the deployment against the UAT org without saving it.