11K Views

CI/CD in Salesforce DX using Gitlab

CI/CD Requirements for Salesfroce DX :

1 Salesforce production org

2 Connected app/Consumer key

3 Gitlab server

4 Gitlab-runner

5 Metadata package ID

In this blog, we will learn how to implement CI/CD with SFDX in 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 from our Salesforce Org. To create a connected app we can follow trailhead official guide link for reference please check :

https://trailhead.salesforce.com/en/modules/sfdx_travis_ci/units/sfdx_travis_ci_connected_app

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

Packaging_Org_CONSUMER_KEY (Client ID)

Packging_Org_USERNAME

JWT_KEY_FILE (SSL 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 which written in YAML with name .gitlab-ci.yml. Basicaly a .gitlab-ci.yml file contains three jobs Build,Test and deploy.

In this script, we will write our sfdx commands in the script section as per our production requirement to start continues 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:

How Script working :

In the above script, I created three jobs, in my first job test I am running jwt-auth command to connect production org and then converting sfdx source to mdapi format using command sfdx force:source:convert and then deploying it to the production org by running sfdx force:mdapi:deploy command and then running apex test command sfdx force:apex:test:run to check the code coverage.

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

In the third job an last job named as managed release again running sfdx force:package1:version:create command with a parameter  –-managedreleased to creating a managed package.

If you have any query you can ask in the comment box.

 

Category(s) Salesforce
. . .

Comment

Add Your Comment

Be the first to comment.

css.php