Refreshing your Pipeline

COPADO

  • Refreshing your Pipeline
  • 27 NOV 2023
  • blog

Copado Refresh

Welcome tothe end of a year and a relaxing start to the summer.

Except if your running an active Pipeline to Production supporting multiple high-performing teams in which case its time to shut everything down and refresh your Pipeline before the serious work starts in the new year.

Why do we do this? There's a couple of reasons that we should refresh every environment we have:

  • Production Drift
    Copado merges changes from your development teams into your production (master or main branch), however these there are also additonal configuration items that can be manually deployed or changes within the salesforce production environment (public group membership, reports, version numbers, etc) that are not captured in the production branch. Now is your chance to snapshot production and get the "actual" state of production reflected in your production branch.
  • Stale Sandboxes
    The first day of every new delivery team or sprint, everyone has a shiny new sandbox instance that is a reflection of production .... after our dev teams have PoC'd functonality, fixed defects, deployed functionality that is later deprecated and generally had development fun, your shiny sandbox looks more like an '87 Honda Civic. Lets give our Dev teams a christmas present and make their Dev environments all new!
  • Merge Performance
    Copado *does not* use a standard branch merge process, I really can't stress this enough! The merge process that Copado uses performs incrmentally slower the older your Test environments are (the more they drift from master) - this isnt really a problem Developers but if you want you Releases to be super quick - refresh your Pipeline.


Steps for a Refresh!

Okay, I've convinced you its a great idea, so what are the steps?

You must refresh top down because each User Story is based on the current master, so first step align Production to your Master branch. To do this take a snapshot making sure to *exclude* stuff you don't care about.
If you need some support on creating a snapshot refer to the Copado Support for the details.
Theres some very good reasons for *not* doing this step, for more details Read Me however as we know exactly what we are doing and have explained to the Dev teams what they need to do, we're all good!

Once you have your Snapshot, follow the procedure for each environment in your Pipeline, starting at the one thats closest to Prod and moving backwards to Dev.

  • Take a Branch Backup
    Take a backup of the current environment branch, this is what Copado believes the sandbox instance contains. I personally have a backup "directory" for this so to complete this:
    login to your git repo,
    create a new branch "backup/environment/2312XX-branch" specifying your environment branch as source "env/environment".
  • Take an Instance Backup
    Take a backup of the current environment instance, this is what is actually in the sandbox. To do this follow the steps for creating a Snapshot pointing to a new branch.
    I use the branch that I created above so "backup/environment/2312XX-instance" specifying your environment branch as source "backup/environment/2312XX-instance".
    Then run your snapshot into backup/environment/2312XX-instance.
  • Move all User Stories back
    Find all User Stories that are currently marked as having been deployed to the Environment you are about to refresh, then move them back one environment. We are removing these stories from the environment so this clearly identifies the last environment they have been deployed into. Repeating this step top down means that all non production stories will eventually appear back in Dev - this step is actually really important
  • Refresh your Environment
    Hit the refresh on your Sandbox, then run your build pipeline to bring your sandbox back on-line. You dont have a build pipline? Reach out to Copado or login to Copado Exchange and grab the Environment builder, or if you neerd something special let me know.
  • Snapshot!
    Once your environment is up and running, create a *new* environment branch. The old branch is worthless and out of date. Don't PR from master into your environment branch - it causes you a bunch of pain later .... create a new branch from master!
    Run a snapshot from your new sandbox into your new branch to align them.
  • Set the last refresh date
    Again this step is critical, set the correct last refresh date in the matching Environment record in Copado. This allows Coapdo to calculate what user stories exist in the higher environments ie those user stories that need to be back promoted.
  • Back Promote
    Manually back promote any user stories from your higher environments to bring your sandbox back up to date.

Dev Environments.

Dev Environments are always special!

Before refreshing your Dev Environments make sure your Dev teams are aware that they are responsible for making sure their work is committed to a feature branch. We're taking a backup of the environment and branch anyway but its always good to have more backups.

We now have two options. We can either refresh the Dev environment or we can introduce a new Dev environment. It's up to you what approach you are going to use. If youre going to bring a new Dev environment into your Pipeline you still must create a new environment branch for the old dev environment and perform the snapshot!

Theres also some additional steps that should be completed on every user story in Dev.

  • Deploy changes *back* to your Dev Environment
    We have removed all user story changes from our dev environment, we need the Dev teams to now put these back into the salesforce dev instance.
    Theres a couple of ways to do this, in my opinion the quickest way is to use sf cli and git.
    
            git switch feature/US-XXXXXXX
            sf project deploy start --source-dir force-app/path-to-metadata --target-org MY-DEV-INSTANCE
                                    
    If you choose not to do this you can craete a deployment from Copado, choosing the commit id of the metadata and deploying to the Dev Instance, its a little more involved but has the benefit of being self-contained inside of Copado. Either way works.
  • Recommit and Rebuild
    Now heres the really important step - make sure your Dev teams "Recommit" and choose the option of "Rebuild Branch" on each User Story!


Wrap up

Okay so what is it that we just did?

The Snapshot into your main or master branch brings that branch up to date, but you need to propergate this back through your pipeline so that every environment has the same commit-id as its starting point. We do this so that each change that is merged into these environments has the same common ancestor.

Once thats done you now need to correct the feature branches for any forward deploying components otherwise they will have a stale (much much older) common ancestor. So to do this you recommit and rebuild - that is, you discard the current feature branch, create a new branch from master - then apply the dev changes from the dev instance into the branch.

Thats it - youre all done!

As always please let me know how your journey with Copado Functions is progressing. Feel free to reach out and chat anytime at AppGenie.com.au..