Skip to content

hardis:source:deploy

Description

sfdx-hardis wrapper for sfdx force:source:deploy that displays tips to solve deployment errors.

Additional to the base command wrapper: If using --checkonly, add options --checkcoverage and --coverageformatters json-summary to check that org coverage is > 75% (or value defined in .sfdx-hardis.yml property apexTestsMinCoverageOrgWide)

Deployment results

You can also have deployment results as pull request comments, on:

Assisted solving of Salesforce deployments errors

Deployment pre or post commands

You can define command lines to run before or after a deployment, with parameters:

  • id: Unique Id for the command
  • label: Human readable label for the command
  • allowFailure: If defined to "true", a failure of this action does not make the deployment job fail
  • context: Defines the context where the command will be run. Can be all (default), check-deployment-only or process-deployment-only
  • runOnlyOnceByOrg: If set to true (default), the action runs only once per target org - subsequent deployments skip it. State is tracked in the "Deployment Actions" PR comment.

Post-deployment actions are never run when the metadata deployment failed: they are reported as not run and are proposed again during the next successful deployment.

After every action runs, its result (✅ success, ❌ failed, 👋 manual) is recorded in a dedicated "Deployment Actions" PR comment - ordered by org (integration → uat → preprod → prod) - regardless of runOnlyOnceByOrg.

When several Pull Requests of the same deployment carry an identical action (same type, phase, user and parameters), it runs once and the other Pull Requests record it as done: see Identical actions run once.

If the commands are not the same depending on the target org, you can define them into config/branches/.sfdx-hardis-BRANCHNAME.yml instead of root config/.sfdx-hardis.yml

You can also keep a single definition and restrict it with includeTargetBranches or excludeTargetBranches (use dev-sandboxes for developer sandboxes).

Example:

commandsPreDeploy:
  - id: 32e7e3d7-eeeb-4162-ae9e-a4013e8439e1
    label: Remove KnowledgeUser right to the user who has it
    command: sf data update record --sobject User --where "UserPermissionsKnowledgeUser='true'" --values "UserPermissionsKnowledgeUser='false'" --json
  - id: bf114a50-8f40-4ac2-bf2b-910139292f76
    label: Assign Knowledge user to the deployment user
    command: sf data update record --sobject User --where "Username='deploy.github@myclient.com'" --values "UserPermissionsKnowledgeUser='true'" --json

commandsPostDeploy:
  - id: ddd0d387-0b84-4ce5-8b0a-a9a370d2ece3
    label: Remove KnowledgeUser right to the user who has it
    command: sf data update record --sobject User --where "UserPermissionsKnowledgeUser='true'" --values "UserPermissionsKnowledgeUser='false'" --json
  - id: 25891b5b-6053-4f91-9416-037e3e3f6e46
    label: Assign Knowledge user to desired username
    command: sf data update record --sobject User --where "Username='admin-yser@myclient.com'" --values "UserPermissionsKnowledgeUser='true'" --json
  - id: a807b752-71dd-4345-a115-413ccd3dbbcc
    label: And to run only if deployment is success
    command: sf sfdmu:run ...
    context: process-deployment-only
    runOnlyOnceByOrg: true

Notes:

  • You can disable coloring of errors in red by defining env variable SFDX_HARDIS_DEPLOY_ERR_COLORS=false

See documentation of Salesforce command

Agent Mode

Supports non-interactive execution with --agent:

sf hardis:source:deploy --agent

In agent mode, all interactive prompts are skipped and default values are used.

Parameters

Name Type Description Default Required Options
agent boolean Run in non-interactive mode for agents and automation
checkcoverage boolean Check Apex org coverage
checkonly
-c
boolean checkonly
coverageformatters option coverageformatters
debug boolean debug
flags-dir option Import flag values from a directory.
forceoverwrite
-f
boolean forceoverwrite
ignoreerrors boolean ignoreErrors
ignorewarnings
-g
boolean ignoreWarnings
json boolean Format output as json.
junit boolean junit
manifest
-x
option flagsLong.manifest
metadata
-m
option metadata
postdestructivechanges option postdestructivechanges
predestructivechanges option predestructivechanges
resultsdir option resultsdir
runtests
-r
option runTests
soapdeploy boolean soapDeploy
sourcepath
-p
option sourcePath
target-org
-o
option Username or alias of the target org. Not required if the target-org configuration variable is already set. true
testlevel
-l
option testlevel NoTestRun NoTestRun
RunSpecifiedTests
RunLocalTests
RunAllTestsInOrg
tracksource
-t
boolean tracksource
validateddeployrequestid
-q
option validateDeployRequestId
verbose boolean verbose
wait
-w
option wait 60
websocket option websocket

Examples

$ sf hardis:source:deploy -x manifest/package.xml --wait 60 --ignorewarnings --testlevel RunLocalTests --postdestructivechanges ./manifest/destructiveChanges.xml --target-org nicolas.vuillamy@cloudity.com.sfdxhardis --checkonly --checkcoverage --verbose --coverageformatters json-summary

Comments