Sub topic 5
Connecting environments and the repository
This chapter assumes you have enabled DevOps Center and created a project, as covered in the previous chapter. You should also know what a sandbox, a Git branch and an OAuth login are. Here you connect the two things a pipeline needs: Salesforce orgs and a Git repository.
What an environment is
An environment in DevOps Center is a Salesforce org that the project knows about and can authenticate to. It can be a development sandbox, an integration or UAT sandbox, or production. Each environment has a name and a login. DevOps Center stores the connection, so you do not need to log in again for each deployment.
The org where DevOps Center is enabled is the one that holds the project records. That org is usually production, or a Developer Edition org that is linked to production.
Connect the repository first
DevOps Center stores every change in Git, so the repository comes first. During project setup you authorize your Git provider, for example GitHub, and choose a repository. The repository should hold a Salesforce DX project.
The repository needs these things:
- A
sfdx-project.jsonfile at the root that names the source directory. - A
.forceignorefile that keeps local tooling files out of deployments. - A main branch that matches the production state of your org.
This is a minimal project file:
{
"packageDirectories": [
{ "path": "force-app", "default": true }
],
"namespace": "",
"sfdcLoginUrl": "https://login.salesforce.com",
"sourceApiVersion": "62.0"
}The following .forceignore excludes editor settings, tests for Lightning web components and the CLI caches:
# .forceignore
**/jsconfig.json
**/.eslintrc.json
**/__tests__/**
.sfdx
.sfConnect the environments
Add one environment for each stage you plan to use. For each one:
- Choose Add Environment and give it a name that matches its role, such as
IntegrationorUAT. - Select the org type, sandbox or production.
- Log in to that org when the browser window opens, and approve access.
- Repeat for every stage, ending with production.
Each environment then maps to one branch in the repository. The next chapter covers how stages use these branches.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Repository does not appear in the list | The Git app is not authorized for that repository | Grant the app access in your Git provider settings |
| Environment login fails | The user lacks API access, or a login IP restriction blocks the connection | Use a user with the right permission set, and check IP rules |
| Deployment includes local files | `.forceignore` is missing or incomplete | Add the patterns and commit the file |
| Wrong org connected | You were logged in to another org in the same browser | Log out first, or use a private window, then reconnect |
Exercise
Why does a project need a repository connected before any pipeline stage is useful, and what file tells Salesforce tooling where the source lives?
Show answer
Every change a work item makes is stored as a commit in Git, and each stage maps to a branch, so without a repository there is nothing to promote. The sfdx-project.json file at the repository root names the package directory, such as force-app, that holds the source.