You are here:
Quick Start: Use Salesforce CLI with DevOps Center
Use Salesforce CLI to automate DevOps Center tasks from the command line. In this quick start, you create and activate a pipeline, manage a work item, and promote changes to the next pipeline stage.
Required Editions
| Available in: Lightning Experience in Professional (API access required), Enterprise, Performance, Unlimited, and Developer Editions |
| Not available in: Government Cloud Plus. Contact your Salesforce account executive for more details. |
| Not available in: EU Operating Zone. EU Operating zone is a special paid offering that provides an enhanced level of data residency commitment. DevOps Center is supported in orgs in the EU that aren't part of EU OZ, per standard product terms and conditions. |
| User Permissions Needed | |
|---|---|
| To create a pipeline: | DevOps Center Admin |
| To promote changes through the pipeline: | DevOps Center Deployment Manager |
For all available flags and options, see Salesforce CLI Command Reference.
Before you begin, complete these tasks.
- Install Salesforce CLI. See Install Salesforce CLI.
- Install the DevOps Center plugin.
sf plugins install @salesforce/plugin-devops-center - Authenticate to the org where DevOps Center is available. This quick start uses
my-devops-orgas the org alias.sf org login web --alias my-devops-org - Create a DevOps Center project from the UI.
- Connect the GitHub (or Bitbucket) repository to your DevOps Center org.
- Set the authenticated org as the default org.
sf config set target-org=my-devops-orgSetting the target org omits
--target-org my-devops-orgfrom subsequent commands. This quick start includes the flag in each command so that the target org is clear.
Set Up a Pipeline
Create a pipeline, add and configure its stages, activate the pipeline, and attach your project.
-
List your projects to find the project ID.
sf devops project list --target-org my-devops-orgCopy the ID of the project that you want to attach to the pipeline. The examples in this quick start use
0Hn000000000001. -
Create an inactive pipeline and connect it to your repository.
sf devops pipeline create --target-org my-devops-org --name "Release Pipeline" --repo https://github.com/myorg/myrepoCopy the pipeline ID from the command output. The examples in this quick start use
0XB000000000001.The pipeline remains inactive until you configure its stages and activate it.
To create a repository while creating the pipeline, use
--create-repowith--repo-type github|bitbucket. -
Add stages to your pipeline. A new pipeline includes a default final stage. Add each new
stage before an existing stage by specifying that existing stage with
--next-stage-id.For example, add an Integration stage.
sf devops pipeline stage add --target-org my-devops-org --pipeline-id 0XB000000000001 --name "Integration" --next-stage-id 0Xc000000000001Copy the stage ID from the command output. The remaining examples use
0Xc000000000005for the integration stage. Repeat the command for each additional stage, such as UAT.
Tip View your pipeline in the DevOps Center UI to get the stage IDs for subsequent commands. Or runsf devops pipeline get --pipeline-id 0XB000000000001. -
Configure each stage. Each stage requires a branch and an environment. Configure stages
from right to left because the final stage must have a branch before you can configure the
stages before it.
Add a branch to the Integration stage. The
--create-vcs-branchflag creates the branch in the repository if it doesn't exist.sf devops stage branch add --target-org my-devops-org --pipeline-id 0XB000000000001 --stage-id 0Xc000000000005 --branch-name integration --create-vcs-branchAdd a sandbox environment to the stage.
sf devops stage environment add --target-org my-devops-org --pipeline-id 0XB000000000001 --stage-id 0Xc000000000005 --environment-name Integration_Org --org-type SandboxA browser window opens so that you can authenticate to the environment. Use
--org-type Productionfor production orgs. In a headless environment, add--no-browserand follow the authentication instructions returned by the command.Repeat the branch and environment commands for every stage. Use the branch name, environment name, and org type appropriate for each stage.
-
Activate the pipeline.
Important You can't modify the pipeline stage after you promote changes through it. Make sure that all stages are configured correctly before you run this command.sf devops pipeline update --target-org my-devops-org --pipeline-id 0XB000000000001 --activate -
Attach your DevOps Center project to the pipeline.
sf devops pipeline project add --target-org my-devops-org --pipeline-id 0XB000000000001 --project-id 0Hn000000000001The pipeline is ready. Create work items in the DevOps Center UI or run thesf devops work-item createcommand.
Manage a Work Item
Complete a development cycle by starting a work item, committing your changes, creating a review, and marking the work item ready to promote.
You can pass --work-item-id instead of --work-item-name
in all work-item and review commands.
-
Set the work item status to In Progress. DevOps Center creates a
feature branch for the work item.
sf devops work-item update --target-org my-devops-org --work-item-name WI-000042 --status "In Progress" -
Fetch the feature branch from the connected repository and check it out in your local
project.
git fetch origin git checkout WI-000042 -
Retrieve changes from your development org. This example retrieves an Apex class from
the org with the alias
my-sandbox.sf project retrieve start --target-org my-sandbox --metadata ApexClass:MyNewClass -
Review the retrieved files, stage them, commit them, and push the feature branch.
git status git add force-app git commit -am "Implement new feature" git push origin WI-000042Adjust the path passed to
git addif your Salesforce DX project uses a different package directory. -
Create a change request (pull request) to merge the feature branch into the target
branch.
sf devops review create --target-org my-devops-org --work-item-name WI-000042 - Wait for your team to approve and merge the change request.
-
Update the work item status to indicate that it's ready for promotion.
sf devops work-item update --target-org my-devops-org --work-item-name WI-000042 --status "Ready to Promote"
Promote a Work Item
Promote the work item to the next pipeline stage. DevOps Center validates the promotion, runs the test suites configured for the target stage, and deploys the changes if the tests pass.
-
Promote the work item, using the work item ID and the target stage ID.
sf devops promote --target-org my-devops-org --work-item-id 0Wx000000000042 --target-stage-id 0Xc000000000002The command output includes a Request ID. Use it to check promotion status.
Status: Completed Message: Work items successfully promoted to UAT. Request ID: a0B000000000001 Promoted Work Items ─────────────────── 0Wx000000000042 -
Use the request ID to check the promotion status.
sf devops request status --target-org my-devops-org --request-token a0B000000000001
When the request status is completed, the work item is available in the target stage.
Common Tasks
Use these commands during your daily development workflow.
-
Promote multiple work items to the same stage. Specify
--work-item-idonce for each work item.sf devops promote --target-org my-devops-org --work-item-id 0Wx000000000042 --work-item-id 0Wx000000000043 --target-stage-id 0Xc000000000002 -
Deploy externally merged changes to a stage that's out of sync with DevOps Center.
sf devops promotion complete --target-org my-devops-org --target-stage-id 0Xc000000000002
Advanced Use Cases
After completing the basic workflow, use these commands for promotions that require more control.
- Custom promotions: Run
sf devops work-item prepareto create the required branches and change requests, and then promote the work item. - Combine work items: Run
sf devops work-item combinewhen multiple work items share metadata or have dependencies and must be promoted together. - Validate before you promote: Run
sf devops promotion validateto check version control and object permissions without promoting the work items.
