CI/CD in Salesforce DX using Gitlab

CI/CD Requirements for Salesfroce DX :

  •  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 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 follow the trailhead official guide link :

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)



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 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 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 is 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
. . .

Comments (2)

Add Your Comment

  • Manoj
    Hi Gajendra,

    We use VSCode with SFDX plugin with SFDX source structure. But we dont use scratch orgs. Can we do deployment using this script? Normal sandbox deployment?

    • gajendra nath
      Hi Manoj,

      As I mentioned in the blog, you need a gitlab server and gitlab runner for starting the deployment, then this script will work.

  • css.php