1

When refreshing Sandboxes I would prefer if all metadata is exactly copied from the source org, but rather we often see files being randomly reshuffled without their content changing when we do a full pull via CICD. This is all fine till multiple people try to merge their change to develop branch, because then we have unnecessary merge conflicts.

The current process is that No-Coders (Admins) base their sandbox by full pushing via Pipeline to their Sandbox, do their changes and retrieve them via a full pull. The pull results in the shuffeled metadata like page layouts being retrieved.

If I do this by hand and break it down for this issue, I'd do the following:

  1. Repo LayoutA has items in order: 1,2,3
  2. Org after cloning has: 1,3,2
  3. Repo->Org: sfdx force:source:deploy force-app/main/default/layouts
  4. Org->Repo: sfdx force:source:retrieve force-app/main/default/layouts
  5. The Org still has the file with order: 1,3,2

Resulting in the following reshuffled file:

Example of reshuffled file

We are also currently working with delta deployments resulting in the page layouts being deployed a lot.

Is there any way to mitigate/solve that problem or is it only something Salesforce can fix?

*Full Push/Pull: source:force:push/pull in a CICD context is similar to doing sfdx force:source:deploy/retrieve -p force-app. For pushing it is identical to sfdx force:source:deploy -p force-app --tracksource. For pulling it pulls all components listed in SourceMember, which for our purpose is similar to retrieving everything in force-app.

2 Answers 2

3

One approach would be to mandate that when a developer makes a change and deploys/pushes that to their scratch org, that before committing they also do a retrieve. That will ensure that the ordering and indenting of the file is "normalised" to exactly the character by character form that is returned by any org.

1
  • Before any feature is started, even after refreshing, an admin first pushes all metadata from the repository to their Sandbox in order to "normalize" (we call it "base") it. Even that does not fix the mentioned issue. You could deploy PageLayout A but it would still be retrieved with lines being scrambled around.
    – Freddy
    Mar 3, 2023 at 9:37
2

This appears to be a problem of your own creation. This answer presumes that when you say "full pull via CICD," you're actually talking about using force:source:retrieve. There is a distinct difference between pull and retrieve. The former uses Source Tracking to detect changes, while the latter naively downloads everything from multiple orgs, wreaking havoc wherever it goes.

A CICD setup needs to (a) treat the repository as the source of truth, and (b) not rely on the metadata in any specific org as being 100% correct. CICD must only use pull commands against the developers' sandbox orgs, and use one, and only one, org to deploy and retrieve from. Most CICD setups I see use Scratch Orgs for this purpose. This eliminates the random noise you get from things like experimental changes the developer left in and differences in API versions between orgs, especially during release windows.

In the DX model, your repo is the Source of Truth. No other org, not even production, can be immune from this policy in order for everything to work smoothly. To keep this process smooth, you must not rely on any specific org being the Source of Truth. You should not be retrieving or pulling from any org directly that isn't under CICD's absolute control.

The entire app life cycle should be as follows.

First, the developer creates/refreshes a Sandbox, or creates a Scratch Org. Next, the developer performs a fetch and pull from the development branch. Third, the developer creates a new branch for building. Fourth, the developer deploys the branch to the org. Fifth, the developer performs any work necessary, and commits any changes. Sixth, the developer goes back to the development branch, performs another pull, then goes back to the feature branch and merges any changes. After this, the branch should be pushed to the remote repo and a pull request created.

At this point, the developer is done. CICD can take over from here. First, it should pull from the development branch, then merge to the feature branch (this should be harmless but reduces race conditions). Then, it should either select a specific, dedicated CICD sandbox, or create a new Scratch Org. After that, it should perform a full deploy and likely Run All Tests; if the deploy fails, abort here and report errors. Then, it should perform a full retrieve and commit any differences. Finally, it can merge back to the development branch and perform any additional deployments needed.

At no point should CICD be pulling anything from any org that is not a dedicated org controlled by CICD. I can't stress this enough. The entire point of the DX model is that orgs are no longer the subjective Source of Truth, but instead, the repo is the objective Source of Truth. This eliminates an entire class of problems, such as those that you've described.

2
  • Hi @sfdxcfox, thanks for your comprehensive answer. To give important insight into our cicd setup, we have two roles Devs and Admins/No-Coders. All issues related to the question are for the Admin-Setup. Our Admins have 3 ways to interact with their and the target sandbox: pull changes from their sb, push to their sb (in dev terms to "sync" their SB/merge develop into their sb) and deploy the pulled changes to the common integration sb. Pulling via CICD from their SB is de-facto the same as retrieve -p force-app but relying on the SourceMember instead of the files already under force-app.
    – Freddy
    Mar 3, 2023 at 9:34
  • TLDR: Admins have limited interaction and do not have local version of the project. They therefor do not have access to a proper pull as they can only pull via CICD which is similar to retrieving all components in the repo as the CICD always starts with zero source tracking information. This de-facto full pull results in shuffled around files being pulled.
    – Freddy
    Mar 3, 2023 at 12:09

You must log in to answer this question.

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