CLI Commands

Updated 2 months ago by Copado Solutions

The Copado CLI is a Salesforce CLI plugin that allows you to perform a wide range of tasks, from logging in to your main Salesforce org to setting a user story or pushing changes to Git.

In this article, we will go over all the commands you can execute with the Copado CLI.

To be able to use the newly added CLI commands you must execute this command first:

sfdx plugins:update
Installs the latest plugins.

Auth Commands

sfdx copado:auth

Displays all the auth commands.

sfdx copado:auth:set

Use this command to configure the CLI to work with a specific org credential using either the username (-u) or the alias (-a).

Usage Options

Description

 -a, --alias=alias

Developers name

 -u, --targetusername=targetusername

Username or alias for the target org; overrides default target org

--apiversion=apiversion

Override the API version used for API requests made by this command

--json

Format output as json

Example

  • sfdx copado:auth:set --targetusername myOrg@example.com
  • sfdx copado:auth:set --alias myAlias
sfdx copado:auth:display

Use this command to show the username that is used to authenticate the Copado CLI.

Usage Options

Description

-s, --showdetails

Use this command to show the username that has been used to authenticate the Copado CLI.

Example

  • sfdx copado:auth:display --showdetails
sfdx copado:auth:grant

Use this command to create a Copado Environment for the specified scratch org.

Usage Options

Description

-e, --environmentname=environmentname

This is a required option. Provide a unique name for the Environment to be created in Copado.

-u, --targetusername=targetusername

Provide the username or alias for the target org. This overrides the default target org.

-w, --wait

Waits for the job to be finished.

--apiversion=apiversion

Overrides the api version used for api requests made by this command.

--json

Formats the output as json.

Example

  • sfdx copado:auth:grant --environmentname MyNewNewCopadoEnvironmentName --targetusername test-acqffozptfsc@example.com

Config Commands

sfdx copado:config

Use this command to display all config commands.

sfdx copado:config:list

Use this command to display the Copado CLI configuration.

sfdx copado:config:set key=value

Use this command to set or update a configuration variable.

Usage Options

Description

key=value

Provide the API key and its value.

--json

Formats the output as JSON.

Example

  • sfdx copado:config:set defaultlistview=[MyNewlyCreatedListView] --json
  • sfdx copado:config:set externalid=[Jira_External_Id__c] --json

Record Commands

sfdx copado:record:open

Use this command to open a record in Salesforce.

Usage Options

Description

-i, --id=id

This is a required parameter. Enter the record id here.

--json

Formats the output as JSON.

Example

sfdx copado:record:open -i <Record Id>

Work Commands

sfdx copado:work

Use this command to display the list of work commands.

sfdx copado:work:set

Use this command to set a user story to work with and create or check out the feature branch.

Usage Options

Description

-c, --credential=credential

Provide the Salesforce org credential name or the local development environment name.

 -e, --extid=extid

Provide the external Id.

 -i, --id=id

Provide the Id of the User Story.

  -s, --story=story

Provide the name of the User Story.

--json

Formats the output as JSON.

Example

  • sfdx copado:work:set --story (Copado User Story Name)
  • sfdx copado:work:set --id (Copado User Story Id)
  • sfdx copado:work:set --extid (External Id Value like JIRA###)
sfdx copado:work:display

Use this command to display information about the current user story. You can create a list view to display additional fields when using this command.

Usage Options

Description

 -i, --id=id

Provide the Id of the User Story.

  -s, --story=story

Provide the name of the User Story.

--json

Formats the output as JSON.

Example

  • sfdx copado:work:display
  • sfdx copado:work:display --story (Copado User Story Name)
  • sfdx copado:work:display --id (Copado User Story Id)
sfdx copado:work:list

Use this command to display the configured listview in the CLI.

Usage Options

Description

  -l, --listview=listview

Enter the User Story list view name to display records from that list view.

--json

Formats the output as JSON.

Example

  • sfdx copado:work:list --listview (Copado listview API Name)

Additional Info

To set a default list view you can use:

sfdx copado:config:set defaultlistview={view name}
sfdx copado:work:open

Use this command to open the user story.

sfdx copado:work:push

Use this command to perform the following actions:

  • Push local changes to Git and Copado.
  • Create all the required data records and attachments in Copado.
  • Create the remote feature branch.

Actions taken by CLI when you use sfdx copado:work:push

  1. Checks if all the changes are committed in the local Git. An error is displayed if there is any uncommitted work.
  2. Checks if changes are not pushed to the remote branch (origin). If not, CLI ask for confirmation and executes git push origin (to feature branch).
  3. Checks if it's not a scratch org and if the userStory.copado__Environment__r.copado__Connection_Behavior__r.copado__DisableEnvironmentBranch__c is disabled.
  4. Creates a User Story commit and an attachment record in Salesforce for all the commit changes from the local checked-in branch.

This command cannot be used if the environment branch is created ahead of the feature branch.

If you create the environment branch ahead of the feature branch, this command generates an error. Hence, manually merge the feature branch with the environment branch and push changes to the environment branch. Why does this happen? If you run work:push instead of git push, you are re-committing local changes(from the environment branch on the user story).

sfdx copado:work:submit

Use this command to submit a user story and applies validations.

Usage Options

Description

  -d, --deploy

Promote and deploy the current USer Story.

   -p, --promote

Set the User Story as promotable.

   -v, --validate

Validates the changes.

--json

Formats the output as JSON.

Example

  • sfdx copado:work:submit --promote true --deploy true --validate true

Environment Commands

sfdx copado:environment:create

Use this command to create an environment.

sfdx copado:environment:list

Use this command to list all environments.

Usage Options

Description

  -n, --name=name

This is a required value. Enter the name of the Environment you want to create.

 -t, --type=type

The default value is Other. Enter the Platform type

--json

Formats the output as JSON.

Example

  • sfdx copado:environment:create --name (Environment Name) --type (Platform  type)

Pipeline Commands

sfdx copado:pipeline:list

Use this command to list all pipelines.

Usage Options

Description

 -a, --all

List all pipelines includig the inactive ones.

--json

Formats the output as JSON.

Example

  • sfdx copado:pipeline:list --all
sfdx copado:pipeline:create

Use this command to create a pipeline.

Usage Options

Description

-b, --branch=branch

The default value is Main. Enter the Main branch for the pipeline.

-d, --deploymenttemplate=deploymenttemplate

Enter the deployment template.

-n, --name=name

This is a required value. Enter the name of the pipeline.

-p, --promotiontemplate=promotiontemplate

Enter the promotion template.

-r, --repository=repository

Enter the Git repository.

-t, --type=type

The default value is Other. Enter the pipeline type.

--json

Formats the output as JSON.

Example

  • sfdx copado:pipeline:create --name (Pipeline Name) --branch (Main branch name) --repository (Git repository Id) --promotiontemplate (Promotion template Id) --branch=(Source branch name) 
  • sfdx copado:pipeline:connection:create -l --pipeline (Copado Pipeline Id) --targetenvironment (Copado Environment Id) --promotiontemplate (Promotion  template Id) --automationtemplate (Automation template Id)
sfdx copado:pipeline:connection:list

Use this command to list all connections to the specified pipeline.

Usage Options

Description

 -p, --pipeline=pipeline

Enter the pipeline Id.

--json

Formats the output as JSON.

Example

  • sfdx copado:pipeline:connection:list --pipeline (Copado Pipeline Id)
sfdx copado:pipeline:connection:create

Use this command to generate a pipeline connection for the specified environment.

Usage Options

Description

-b, --sourcebranch=sourcebranch

Enter the branch name for the source environment.

-d, --destinationbranch=destinationbranch

Enter the branch name for the destination environment. This is a mandatory requirement if the target environment is not a part of the pipeline yet.

-e, --sourceenvironment=sourceenvironment

Enter the Source Environment Id from which deployments will originate.

-g, --snapshot

The default value is true. Whether or not a snapshot of the environment is required.

-l, --local

The default value is false. Creates a local environment.

 -p, --pipeline=pipeline

Enter the pipeline record Id.

 -t, --destinationenvironment=destinationenvironment

Entire the Environment Id to which deployments are targeted.

--json

Formats the output as JSON.

Example

  • sfdx copado:pipeline:connection:create --pipeline (Copado Pipeline Id) --targetenvironment (Copado Environment Id) --sourceenvironment (Copado Environment Id) --sourcebranch=(Source branch name)   --destinationbranch=(Destination branch name)
  • sfdx copado:pipeline:connection:create --local --pipeline (Copado Pipeline  Id) --targetenvironment (Copado Environment Id)
sfdx copado:record:open

Use this command to open the record in Salesforce.

Usage Options

Description

 -i, --id=id

This is a required value. Enter the record Id.

--json

Formats the output as JSON.

Example

  • sfdx copado:record:open -i (Record Id)

Repository Commands

sfdx copado:repository:list

Use this command to list all the repositories.

Usage Options

Description

--json

Formats the output as JSON.

Automation Commands

Use these commands to list and run automation templates in a simple way from the CLI. You can extend Copado into your local environment without going into SFDC. As an admin or developer if you need to create a custom setting record with the API name of automation template, you must execute an automation template from CLI.

sfdx copado:automation:upgrade

Use this command to fetch all the Automation Template (AT) records stored in the custom setting and store it locally (on developer’s laptop at the location: $HOME/.copado/username.json).

Usage Options

Description

--json

Formats the output as JSON.

sfdx copado:automation:list

Use this command to display the list of AT available locally..

Usage Options

Description

--json

Formats the output as JSON.

sfdx copado:automation:help

Use this command to display the description of the AT, and list all input parameters required for the AT to run..

Usage Options

Description

 -n, --name=name

Enter the name of AT.

--json

Formats the output as JSON.

Example

  • sfdx copado:automation:help -n (Automation Template Name)
sfdx copado:automation:run
  • This calls a generic WS that creates an instance of the AT.
  • Executes it.
  • If successfully executed, it returns the generated DeploymentId.

Usage Options

Description

 -f, --parameterfile=parameterfile

A json file containing all the parameters. This file is generated using $ sfdx copado:automation:help -n (templateName) --json command

 -n, --name=name

Enter the name of AT.

--json

Formats the output as JSON.

Example

  • sfdx copado:automation:run -n (Automation Template Name)

Additional Info

This command executes an AT in two modes—interactive and no-prompt mode.

  • Interactive Mode
    sfdx copado:automation:run -n (Automation Template Name)
    It will switch to interactive mode and ask for TemplateName and all the input parameters input required to run the AT.
  • No-prompt Mode
    sfdx copado:automation:run -n {TemplateName} -f {path to the file containing the JSON format of all parameters needed to run the AT}
    Here you provide all the parameters inline, hence you will not get any prompt.
sfdx copado:automation:result

Use this command for the following actions:

  • To show the deployment status.
  • To show the amount of steps and their statuses. For example, 2 steps of 5 completed.
  • To show the details of the step result, in case of an error

Usage Options

Description

 -i, --id=id

This is a required value. Enter the result Id.

   -n, --name=name

Shows the Function Logs by default. Enter the File Name to retrieve the file containing this keyword.

--json

Formats the output as JSON.

Example

  • sfdx copado:automation:result -i (Result Id)
  • If it is a binary file you should save it using
    sfdx copado:automation:result -i (Result Id) -n (Binary File Name) --json > fileName


How did we do?