1

I have a SFDX project on github which is linked to circleci. I'm using docker executor in circleci. Now I don't want to create a new scratch org everytime my workflow runs on circleci after a commit.

I want to use one scratch org and make recurring deployments to that. Now the easiest way for authenticating the scratch org everytime on the docker executor is to use the url based authentication flow for scratch orgs. This requires me to push a file (which contains the authentication URL) to my docker container which I can then access through sfdx force:auth:jwt:grant. Now I have two challenges here, I'm not sure how to retrieve my docker container id or name. Since that is required for my "docker cp" command. Below are related lines from the snippet of my config.yml and the related script file.

version: 2
 jobs:
 build:
  working_directory: ~/SalesforceApp
  docker:
   - image: circleci/node:latest
  steps:
   - checkout
   - setup_remote_docker

  sfdx force:auth:jwt:grant --clientid $SFDC_CONSUMER_KEY --jwtkeyfile keys/server.key --username $SFDC_USERNAME --setdefaultdevhubusername -a DevHub

Not sure if my understanding of docker executor is totally correct at this stage so apologies for that in advance as I'm still new to the world of CI/CD.

2

Scratch orgs are intended to be disposable: you create an org, populate it with your metadata, do work in it, capture any work you wish to persist, and then destroy the org.

Scratch orgs generally should not be used persistently, and in particular this is likely to cause problems in a CI context where you may be running builds on radically different branches frequently - i.e., branches with very divergent metadata. Note that scratch orgs also have a fixed, finite lifespan that maxes out at 30 days.

I would strongly encourage you not to try to use scratch orgs as persistent orgs. Instead, use one org per CI job and delete it when finished.

Salesforce partners' Partner Business Orgs come with much higher scratch org limits (at least 80/day for active partners) when used as the Dev Hub, relative to the 6/day available in Developer Edition orgs. You can request free Salesforce DX-only licenses to allow users to log in and manage scratch orgs in the PBO.

| improve this answer | |
  • Thanks David, I understand that and agree with your point. The plan is to create a new one every 30 days. The challenge with the suggested approach is that you can only create 6 orgs per 24 hours from a dev account. This limits my CI pipeline builds to 6 commits which is quite low and hampers development as I'm actively working on a Salesforce appexchange app. – Zarq Iqbal Jan 20 at 18:11
  • @ZarqIqbal Are you a Salesforce partner? Your Partner Business Org has massively higher limits. – David Reed Jan 20 at 18:20
  • Yes I do have a partner business org with 2 licenses. I have environment hub enabled in it and from there I created a partner developer org and even an enterprise org but both of those have scratch org limits equivalent to a normal dev org. Those limits being: 3 active scratch orgs 6 daily scratch orgs (can create 6 in a 24 hour window) – Zarq Iqbal Jan 20 at 19:02
  • 3
    That's correct. Only the Partner Business Org itself has access to the enhanced limits, and must be used as the Dev Hub. You can request SFDX-only licenses for free to facilitate this use case. – David Reed Jan 20 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.