Sub topic 5
Connecting environments and the repository
This chapter covers how DevOps Center links to the orgs and the Git repository that make up a project. It assumes you can already do the following:
- Work with sandboxes and metadata.
- Use Git branches, commits and pull requests.
- Enable DevOps Center and create a project, as covered in the previous chapter.
What an environment is in DevOps Center
An environment is a Salesforce org that DevOps Center knows about and can deploy to or retrieve from. Each environment has these properties:
- A name, such as
Dev1,Integration,UATorProduction. - An authenticated connection to a real org.
- A role in the project. It is either a development environment, where people build changes, or a pipeline stage environment, where changes are deployed and tested.
An environment is not a stage. A stage is a position in the pipeline, and an environment is the org attached to that position. You will design stages in the next chapter. Here you create and authenticate the orgs those stages will use.
What you connect
A project needs two kinds of connection:
| Connection | Purpose | Authenticated with |
|---|---|---|
| Salesforce orgs | Deploy and retrieve metadata, run tests | A Salesforce login for each org |
| Git repository | Store the source of truth and branches | A GitHub account (or another supported Git provider) |
DevOps Center sits between the two. It reads changes from a development org, writes them to a branch in the repository, and deploys from the repository to the stage orgs.
Environment types and what to use for each
Use a sandbox for every environment except the final one. The type you choose affects data volume, refresh behavior and cost.
| Environment use | Typical org type | Notes |
|---|---|---|
| Individual development | Developer or Developer Pro sandbox, one per developer | Small, fast to refresh, holds only metadata |
| Integration | Developer Pro or Partial Copy sandbox | Where merged work items are first combined |
| UAT or staging | Partial Copy or Full sandbox | Pick based on how realistic the test data must be |
| Production | Production org | The last stage in the pipeline |
Give each developer their own development environment. Two people sharing one org can overwrite each other's work, and that makes change tracking unreliable.
Connecting the repository
DevOps Center works from a repository that holds your project in Salesforce DX source format. The repository must have a layout that DevOps Center can read. The key file is sfdx-project.json at the root, which names the source directory that Git tracks.
{
"packageDirectories": [
{ "path": "force-app", "default": true }
],
"namespace": "",
"sfdcLoginUrl": "https://login.salesforce.com",
"sourceApiVersion": "62.0"
}Check these points before you connect:
- The
pathvalue must match a real folder in the repository. If it doesn't, DevOps Center finds no metadata to track. sourceApiVersionshould be a version that every org in the pipeline supports.- The authenticated Git user needs permission to create branches and open pull requests in the repository.
During project creation you pick the Git provider, sign in, and select the repository. DevOps Center then creates the branches that back your pipeline stages. Each stage maps to one branch, such as main for Production and UAT for the UAT stage.
Keeping tooling files out of deployments
Local editor settings and caches are not metadata. If they reach a deployment, they cause errors or clutter. A .forceignore file excludes them:
# .forceignore
**/jsconfig.json
**/.eslintrc.json
**/__tests__/**
.sfdx
.sfCommit this file to the repository root so every developer and every pipeline run uses the same rules.
Authenticating an environment
For each environment you add, DevOps Center opens a Salesforce login. You sign in as a user who can deploy to that org. Keep these rules in mind:
- Use a named user with the required permissions, not a shared account. Deployments and commits are then traceable to a person.
- Authenticate to the correct org. Sandbox logins go through
test.salesforce.com, and Production logins go throughlogin.salesforce.com. Choosing the wrong one is the most common cause of a failed connection. - Use a user whose password and multi-factor authentication settings won't cause the connection to lapse unexpectedly.
If a connection later expires or the user is deactivated, deployments to that environment fail until someone re-authenticates it.
Checking a connection outside DevOps Center
The Salesforce CLI lets you confirm that an org accepts a deployment before you rely on it in the pipeline. This command runs a validation-only deployment with local tests:
sf org login web --alias uat
sf project deploy start --source-dir force-app --target-org uat --dry-run --test-level RunLocalTestsThe --dry-run flag checks the deployment without saving any change to the org. If this command fails because of the login or permissions, the DevOps Center connection to the same org will fail for the same reason.
Verifying that the repository and the stages line up
After the connection is made, confirm that the branches reflect the stages you expect. Comparing two stage branches shows what a promotion would carry:
git fetch origin
git log --oneline origin/main..origin/UATThe output lists commits that are on the UAT branch but not yet on main. An empty result means the stages match. Commits in the list are the changes waiting for promotion.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Authentication loops or fails for a sandbox | Signed in through the production login URL | Re-authenticate through the sandbox login |
| Project shows no metadata | `path` in `sfdx-project.json` doesn't match a folder | Correct the path and commit it |
| Cannot create branches during setup | Git user lacks write access | Grant write access on the repository |
| Deployments fail after working before | The authenticated user was deactivated or lost permissions | Re-authenticate with a valid user |
| Stage branches differ unexpectedly | Someone committed directly to a stage branch | Stop direct commits and reconcile with a pull request |
Summary of the setup order
- Create or choose a sandbox for each stage and each developer.
- Prepare the repository with
sfdx-project.jsonand.forceignore. - Authenticate the Git provider.
- Authenticate each Salesforce environment with a named user.
- Check the connections, with a dry-run deployment if you want proof.
Exercise
A new project connects successfully to GitHub, but DevOps Center shows no metadata from the repository. The repository contains a src folder with the metadata, and sfdx-project.json lists force-app as the package directory. What is wrong, and how do you fix it?
Show answer
The path in sfdx-project.json points to force-app, but the metadata lives in src, so DevOps Center finds nothing to track. Either change the path to src or move the metadata into force-app, then commit the change to the repository.
Exercise
A teammate authenticates a UAT sandbox by using the production login URL and the connection fails. Why, and what do you do?
Show answer
Sandbox users sign in through the sandbox login (test.salesforce.com), and the production login URL does not recognize them. Re-authenticate the environment through the sandbox login.