Start a Project

How to start the CI/CD in Salesforce DX using Gitlab

Prerequisite For CI/CD Implimentatation In Salesfroce:

In this blog, we will learn how to implement CI/CD with SFDX using GitLab. To start CI/CD in salesforce DX, we required a connected app for JWT-based authentication to our Salesforce Org. We can create a connected app in our Salesforce Org.

To create a connected app in your org, follow the official Salesforce DX Developer Guide link :

After creating a connected app we can test our connection with our packaging org by running the command with the below-mentioned parameters.

Packaging_Org_CONSUMER_KEY            (Client ID)

Packging_Org_USERNAME                         (User name of your org)

JWT_KEY_FILE                                            (Self-signed Key).

“sfdx force:auth:jwt:grant –clientid ${Packaging_Org_CONSUMER_KEY} –username ${Packging_Org_USERNAME} \ –jwtkeyfile ${JWT_KEY_FILE} –setdefaultdevhubusername”

After creating a connected app we required a script with SFDX commands to start a pipeline written in YAML with the name .gitlab-ci.yml. Basicaly a .gitlab-ci.yml file contains three jobs like Build,Test and deploy.

In this script, we will write our sfdx commands in the script section as per our production requirement to start continuous integration on salesforce. As per our production requirement, I have created a script to test, deploy and release the salesforce app versions.

Content of .gitlab-ci.yml is here:

Let’s know how the Script is working :

In the above script, I have created three jobs, in the first job test, I am running the command “sfdx force:auth:jwt:grant” to connect the production org.

Then converted sfdx source code to mdapi format using the command “sfdx force:source:convert”

Then deployed the project to the production org by running the command “sfdx force:mdapi:deploy”  after deployment, I am running apex test command “sfdx force:apex:test:run” to check the code coverage.

Create a beta package:

In the second job beta-release first connects to the salesforce Org and runs “sfdx force:package1:version:create” command to release the beta version of the salesforce package which I deployed in my first job.

Create a managed package:

In the third job, the last job named managed release again runs “sfdx force:package1:version:create” command with the parameter  “--managedreleased” to create a managed package.

If you have any queries, you can ask in the comment box.

Exit mobile version