It's All Writing.

Writing makes you happy.

How to run CI ( Continuous Integration ) on Gitlab ( executing Test code and deploying code to salesforce organization )


  • Apex


First I prepare deployed Apex and Apex which tests that. The Apex code are shown as below.


CI in gitlab comes to move by putting .gitlab-ci.yml in the route of a repository of gitlab. The example is shown as below.

When you execute git push, this process is carried out.
The summary of the process written in .gitlab-ci.yml is as follows.

in before_script section

  1. install force-dev-tool
  2. login production organization ( using access information written in config/.orgs.json ).
  3. remove directories exclude classes/, pages/, staticresources/, triggers/ and aura/ in force-app/main/default/ directory ( this directory structure is the standard structure with using VSCode's Salesforce Extension Pack ).
  4. make force-app/main/default/package.xml to deploy modules which are ApexClass, ApexComponent, ApexPage, ApexTrigger, StaticResource and AuraDefinitionBundle.

in test_deploy_production section

  1. run force-dev-tool deploy as test only mode.

in deploy_production section

  1. run force-dev-tool deploy as deploy to production environment.


The example of config/.orgs.json is shown as below.