0

When I tried to build a dynamic script in GitHub Actions using SFDX, I have been puzzled by the weird behaviour of sfdx force:user:list --json command in linux version of SFDX.

In MacOS version of SFDX, the following command

username=$(sfdx force:user:list --json | jq '.result[-1].username' -r)

is able to return the username of the current user and then I could use ${username##*.} syntax to get the sandbox name from username (assuming the username has [email protected] format).

  echo "Username = $username"
  echo "Last part is ${username##*.}"

In MacOS, this returns [email protected] and sandbox correspondently but in Linux CI machine it returns null.

How can I get this working in my CI Process?

1 Answer 1

0

The command sfdx force:user:list --json in Linux version of SFDX CLI returns

{
  "status": 1,
  "name": "notFoundOnDevHub",
  "message": "The scratch org does not belong to the dev hub username [email protected].",
  "exitCode": 1,
  "actions": [
    "Specify the dev hub username that the scratch org belongs to with --targetdevhubusername or set a default run \"sfdx force:config:set defaultdevhubusername=<username>\"."
  ],
  "commandName": "UserListCommand",
  "stack": "notFoundOnDevHub: The scratch org does not belong to the dev hub username [email protected].\n    at ALMError (/usr/local/lib/sfdx/node_modules/salesforce-alm/dist/lib/core/almError.js:50:19)\n    at /usr/local/lib/sfdx/node_modules/salesforce-alm/dist/lib/core/scratchOrgApi.js:608:31\n    at tryCatcher (/usr/local/lib/sfdx/node_modules/bluebird/js/release/util.js:16:23)\n    at Promise._settlePromiseFromHandler (/usr/local/lib/sfdx/node_modules/bluebird/js/release/promise.js:547:31)\n    at Promise._settlePromise (/usr/local/lib/sfdx/node_modules/bluebird/js/release/promise.js:604:18)\n    at Promise._settlePromiseCtx (/usr/local/lib/sfdx/node_modules/bluebird/js/release/promise.js:641:10)\n    at _drainQueueStep (/usr/local/lib/sfdx/node_modules/bluebird/js/release/async.js:97:12)\n    at _drainQueue (/usr/local/lib/sfdx/node_modules/bluebird/js/release/async.js:86:9)\n    at Async._drainQueues (/usr/local/lib/sfdx/node_modules/bluebird/js/release/async.js:102:5)\n    at Immediate.Async.drainQueues [as _onImmediate] (/usr/local/lib/sfdx/node_modules/bluebird/js/release/async.js:15:14)\n    at processImmediate (internal/timers.js:456:21)\nOuter stack:\n    at Function.wrap (/usr/local/lib/sfdx/node_modules/salesforce-alm/node_modules/@salesforce/core/lib/sfdxError.js:171:27)\n    at UserListCommand.catch (/usr/local/lib/sfdx/node_modules/salesforce-alm/dist/ToolbeltCommand.js:248:46)\n    at async UserListCommand._run (/usr/local/lib/sfdx/node_modules/@salesforce/command/lib/sfdxCommand.js:97:13)\n    at async Config.runCommand (/usr/local/lib/sfdx/node_modules/@oclif/config/lib/config.js:173:24)\n    at async Main.run (/usr/local/lib/sfdx/node_modules/@oclif/command/lib/main.js:27:9)\n    at async Main._run (/usr/local/lib/sfdx/node_modules/@oclif/command/lib/command.js:43:20)\n    at async Object.run (/usr/local/lib/sfdx/dist/cli.js:32:20)",
  "warnings": []
}

So instead other commands can be used which work well on Linux SFDX like following

username=$(sfdx force:org:display --json | jq '.result.username' -r)
      echo "Username = $username"
      echo "Last part is ${username##*.}"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .