Coming Soon --- For a fully guided walk through of setting up and configuring this sample, see the Continuous Integration Using Salesforce DX Trailhead module.
This repository shows one way you can successfully setup Salesforce DX with Circle CI. We make a few assumptions in this README:
- You know how to get your Github repository setup with Circle CI. (Here's their Getting Started guide.)
- You have properly setup JWT-Based Authorization Flow (i.e. headless). I recommend using these steps for generating your Self-Signed SSL Certificate.
If any any of these assumptions aren't true, the following steps won't work.
-
Make sure you have the Salesforce CLI installed. Check by running
sfdx force --help
and confirm you see the command output. If you don't have it installed you can download and install it from here. -
Confirm you can perform a JWT-based auth:
sfdx force:auth:jwt:grant --clientid <your_consumer_key> --jwtkeyfile server.key --username <your_username> --setdefaultdevhubusername
Note: For more info on setting up JWT-based auth see Authorize an Org Using the JWT-Based Flow in the Salesforce DX Developer Guide.
-
Fork this repo into your github account using the fork link at the top of the page.
-
Clone your forked repo locally:
git clone https://github.com/<git_username>/sfdx-circleci.git
-
Encrypt and store the server.key generated above using the instructions below.
"Circle does a nice job of allowing you to set environment variables inside the UI in a protected way." (attribution to Kevin O'Hara)
- First, we will generate a key and initializtion vector (iv) to encrypt your server.key file locally. The key and iv will be used by Circleci to decrypt your server key in the build environment.
$ openssl enc -aes-256-cbc -k <passphrase here> -P -md sha1 -nosalt
key=E5E9FA1BA31ECD1AE84F75CAAA474F3A663F05F412028F81DA65D26EE56424B2
iv =E93DA465B309C53FEC5FF93C9637DA58
Make note of the
key
andiv
values output to the screen. You will use the values followingkey=
andiv =
to encrypt yourserver.key
in the next step.
- Encrypt the
server.key
using the newly generatedkey
andiv
values. Thekey
andiv
values should only be used once, don't use them to encrypt more than theserver.key
. While you can re-use this pair to encrypt other things, it is considered a security violation to do so. Every time you run the command above, a newkey
andiv
value will be generated. IE, you can not regenerated the same pair, so if you lose these values you will need to generated new ones and encrypt again.
openssl enc -nosalt -aes-256-cbc -in assets/server.key -out assets/server.key.enc -base64 -K <key from above> -iv <iv from above>
- Store the
key
,iv
and contents ofserver.key.enc
as protected environment variables in the Circleci UI. These valus are considered secret so please treat them as such.
-
From you JWT-Based connected app on Salesforce, retrieve the generated
Consumer Key
and store in a Circleci environment variable namedHUB_CONSUMER_KEY
using the Circleci UI. -
Store the user name that you use to access your Dev Hub in a Circleci environment variable named
HUB_SFDX_USER
using the Circleci UI. Note that this username is the username that you use to access your Dev Hub. -
Store the
key
andiv
values used above in Circleci environment variables namedDECRYPTION_KEY
andDECRYPTION_IV
respectively. When finished setting environment variables you environment variables setup screen should look like the one below.
8 ) IMPORTANT! Remove your server.key
: rm assets/server.key
, you should never store keys or certificates in a public place.
And you should be ready to go! Now when you commit and push a change, your change will kick off a Circle CI build.
Enjoy!
If you find any issues or opportunities for improving this repository, fix them! Feel free to contribute to this project by forking this repository and make changes to the content. Once you've made your changes, share them back with the community by sending a pull request. Please see How to send pull requests for more information about contributing to Github projects.
If you find any issues with this demo that you can't fix, feel free to report them in the issues section of this repository.
Test