Automating Salesforce DX using Babashka

#salesforce#clojure#babashka

Automating Salesforce DX using Babashka

We are a Salesforce ISV. We use the latest tooling when we can. That means the sfdx and sf CLI tools, scratch orgs and second generation packaging.

In this environment, it’s a common requirement to script the creation of orgs for development and continuous integration.

There are a few different options for scripting. This is how we do it. Maybe you should too?

The Problem

Scripting is tedious work. Scripting CLIs adds complexity. We just want it done so we can focus on features.

The first choice is which scripting language/runtime to use? Common choices are:

  • bash
  • powershell
  • .bat files

Immediately you are faced with a choice. These options are operating system specific:

  • Yes you can install WSL2 on windows and do everything in bash but it’s still bash scripting. Not a very sharp tool.
  • Yes powershell is powerful but how will you run this in CI where it’s common to use Docker containers running linux?

Secondly, building these scripts can be painful. You need to run/re-run each step and check the results using your scripting language. Anyone who maintains these scripts knows this problem. We’d like to offer an alternative.

The Solution

Nextdoc is a full-stack Clojure(script) app so we use Clojure for our scripting needs.

There are many Clojure runtimes but the best for scripting is Babashka because it starts as fast as bash/powershell etc.

Babashka includes a declarative task runner and CLI argument parser which are nearly always needed for scripting. It also supports most of the common libraries used in the Clojure ecosystem. This is bringing a gun to a knife-fight.

Being a LISP it also offers a REPL which makes creating and testing tasks much faster.

Babashka is portable i.e. it runs on Windows, Mac and Linux. Everywhere you need it.

We work with many ISV’s so we decided to open source our tooling to support our partners and the community.

That’s enough reading. Here’s how you use it…