/devTrailsZuerich-CircleCI20-SalesforceDX

Demo of using CircleCI 2.0 with SalesforceDX for Continuous Integration

Primary LanguageApex

Introduction to Salesforce DX - DevTrails Zürich

This repo is a clone of https://github.com/Szandor72/LightningWorkbench stripped to bare DX basics. The original packaged source can be found in ./packaged

Dev, Build and Test - all in one push

We will be using circle ci 2.0 for the purposes of this demo. All the amazing stuff you can do with DX is somewhat screencast scripted in commands.txt - you can follow along easily. There's also some best practices shared in there.

In order to get Continuous Integration up and running, create a connected app, a server.crt and server.key following these steps: https://trailhead.salesforce.com/modules/sfdx_travis_ci/units/sfdx_travis_ci_connected_app

Important: Do not use 'all user may self authorize'. Use Profiles or Permission Sets.

Circle CI

Head over to https://circleci.com and sign up with your github account and add your new project/repo.

We will need to set up a few environment variables in Circle CI in order to securly store our credentials.

  • First create a hex version of your server key (bash)
$ xxd -p server.key >> server.key.hex'

Now add the following environment vars at https://circleci.com/gh/$GithubUsername$/$RepositoryName$/edit#env-vars

  • DX_USERNAME: your dev-hub username
  • DX_CONSUMER_KEY: the connected app's consumer key
  • SSL_SERVER_KEY_HEX: the content of server.key.hex

CircleCI 2.0 is pretty straigtht forward to read without any prior experience. That's a huge improvement in comparison to 1.0. Have a look at .circleci/config.ymland for a general idea how to work with branch-level workflows: https://github.com/CircleCI-Public/circleci-demo-workflows/blob/sequential-branch-filter/.circleci/config.yml

Nice demo, how can I use this for real stuff?

  • create another connected app in your org (sandbox/production)
  • authenticate dx with ALIAS deploy
  • add the following to your build:
  sfdx force:source:convert -r force-app -d src
  sfdx force:mdapi:deploy -d src/ -u deploy --wait 2

Resources

DX Plugins to check out

DX can be extended in various ways, here are my two current favourites

  • https://www.npmjs.com/package/sfdx-l18n-plugin A plugin for the Salesforce CLI built by Mikkel Flindt Heisterberg to allow you to update the localization values on the created users object. This allows you to set the user interface language, the locale of the user (date/time formats) and the timezone of the user from the command line.

  • https://www.npmjs.com/package/sfdx-msm-plugin lots of supercool utilities. E.g. Retrieving a package, unzipping, converting