Sfdx is now an essential tool to set up in salesforce projects. It is used to ease the development of LWC and also to facilitate the continuous delivery of the code and its versioning.
With the experience gained on my latest projects in SFDX release management, I made a small guide for setting up a simple continuous delivery system in the frame of an sfdx project.
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
sfdx continuous Integration with Jenkins on aws (Part II)
1. Salesforce developer journey in
sfdx release management world
( part II )
1 - Create AWS Instance
> 2 Install Jenkins and sfdx on AWS Instance
> 3 Setup Pipeline 1 : automate testing your code
4 - Setup Pipeline 2 : automate delivery in a sandbox
Badbaxx - Salesforce developer
@84D84XX
2. “Back to salesforce side”
1 - Overview Lifecycle
2 - Settings dev hub
3 - Install Essentials Tools on aws (sfdx + git)
4 - Create Github Account and project
5 - Setup Variables Jenkins
6 - Create the Job
3. An Overview of sfdx CI environment
SO
repo
repo
checkout
repo
dev. computer
sfdx push
sfdx pull
git push
git pull
● pipeline 1 : test code
● pipeline 2 : delivery
● pipeline n : ...
Trigger by webhook or CRON
4. pipeline 1 : basic test on code in our repo
repo
Run apex test
04
● Run apex test (local)
sfdx force:apex:test:run
Push to Scratch Org
03
➔ push data from the repo git
sfdx force:source:push
Create Scratch Org
02
➔ Connect to devhub and create SO
sfdx force:org:create
01
Checkout
repo
SO
SO
5. 2 - Setup Salesforce side
We need now a developer org to continue. You can create one at :
https://developer.salesforce.com/signup
The first step is to activate dev hub option :
From Setup, enter Dev Hub in Quick Find box > select Dev Hub.
To enable Dev Hub, click Enable.
6. Create jwt token as explain in salesforce
documentation
https://developer.salesforce.com/docs/atlas.en-us.s
fdx_dev.meta/sfdx_dev/sfdx_dev_auth_key_and_c
ert.htm
Create jwt token
2 - Setup Salesforce side
7. Create a connected app as explained in the
documentation (step 1 to 15)
https://developer.salesforce.com/docs/atlas.en-us.
sfdx_dev.meta/sfdx_dev/sfdx_dev_auth_connecte
d_app.html
Create connected App
2 - Setup Salesforce side
8. With enabling dev hub in our org, we can now execute sfdx command on it
The Connected app will permit Jenkins to authenticate with the dev hub org and
communicate
The jwt token is the way we will authenticate to the dev hub, via the connected app
2 - Setup Salesforce side
9. 3 - Install git on your aws Instance
Back in puTTY (see part 1) we will install
git with the command :
sudo yum install git
You can verify that it was install with the
command
which git
path where git is install : /usr/bin/git
10. 3 - Install sfdx CLI on your aws instance
You can Install the sfdx cli following salesforce documentation, with the
following command in puTTY :
wget
https://developer.salesforce.com/media/salesforce-cli/sfdx-linux-amd
64.tar.xz
mkdir sfdx
tar xJf sfdx-linux-amd64.tar.xz -C sfdx --strip-components 1
./sfdx/install
You can get the installation repository with the command : which sfdx
https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_install_cli.htm
11. Installing Git and sfdx-cli will permit us to use those software in Jenkins
With sfdx-cli we will use sfdx command to interact with the dev hub and SO
With git, we will checkout our repo on github and get the code we want to test and
push to SO
3 - Installing tools
12. 4 - Set up your github project
https://github.com/baddbaxx/sfdx-project.git
go to your github account
click “+” and import
repository
in clone URL insert :
https://github.com/baddbaxx/
sfdx-project.git
in Name of the new repo.
insert sfdx-project
=> Begin import
13. 5 - Configure Variables
● Credentials
We will add the server.key file (created at the connected app step)
to Jenkins credentials :
Kind Secret file
Scope Global
Id SecretFile
14. 5 - Configure Variables
● Environment variables
Check the environment variable checkbox and add those
4 variables
HUB_ORG_DH : The username for the Dev Hub org, such
as badbaxx@mydomain.com
SFDC_HOST_DH : The login URL of the Salesforce instance
that is hosting the Dev Hub org. The default is
https://login.salesforce.com
CONNECTED_APP_CONSUMER_KEY_DH : The consumer key
that was returned after you created a connected app in
your Dev Hub org.
JWT_CRED_ID_DH : The credentials ID for the private key
file that you stored in the Jenkins Admin Credentials
interface
15. We will now create the first jenkins job. Select New Item and Freestyle project to star
6 - Create the first job
16. 6 - Create the first job
Select > Pipeline script from SCM
SCM > Git
Repository > Url to your github project
Branch > */master
Script path > Jenkinsfile (in root directory)
Save
17. and ...
6 - Create the first job
Click buld Now to start the build and play the
script contained in the Jenkins File
18. fail…
let’s look at the log to debug :
click the little arrow near your build
and select
6 - Create the first job
19. 6 - Create the first job
As you can see, the problem come from a security issue:
you need to approve the signature
=> click on the link Administrators can decide whether to ...
20. click approve and go back to the job and
click again
6 - Create the first job
21. you should need to launch again the job 2
time and approve the same way
(See possible trouble next page)
6 - Create the first job
FInally ...
22. 6 - Create the first job
TROUBLE !!!
1- You can only have 3 SO at the same time with a developer edition.
> The job will fail if you already have 3 SO associated with your dev hub
solution : go to your dev hub instance and delete SO
(App Laucher > Active Scratch Org)
2- You can only create a limited number of SO per day. If you reach this point,
you will need to wait 24h to create a new one (and success this pipeline)
23. 6 - Create the first job
you can see all element from your repo deployed
your can see info for all test class (only one here)
Read the log :
24. Part II Summary
We set up Jenkins on aws to use sfdx-cli
We set up Jenkins on aws to use git
We create a sfdx project in github
We create a basic pipeline to :
- Create a Scratch Org (SO)
- Push Git project in the SO
- launch test class
In last part, we will see :
Deploy the sfdx-project in sandbox with jenkins
25. Restart Jenkins
sudo service jenkins restart
Annexe
Find something on your aws instance
which <software>
Navigate in file and folder with puTTY
https://www.computerhope.com/issues/chusedos.htm
Update sfdx
sfdx update