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

Updated 7 September 2023

Prerequisite For CI/CD Implimentatation In Salesfroce:

  •  Salesforce production org
  • Connected app/Consumer key
  • Gitlab server
  • Gitlab-runner
  • Metadata package ID
  • Self-signed SSL certificate

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.

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


9 comments

  • rajeswari22
  • vinayak
  • Avinash
    • gajendra nath (Moderator)
  • Manoj
    • gajendra nath (Moderator)
      • Aadi
        • gajendra nath (Moderator)
          • sivakumar
  • Start a Project




      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home