CI/CD is a utility for Gitlab that is used to scan the project for errors and/or low-quality code, to make the project convenient for deployment on Scratch orgs and easy to configure for use. Checking with the CI/CD pipeline will help you determine what fixes and improvements need to be made to successfully deploy the project to any new org.
Example of CI/CD usage on our project for Advantage application development. The steps below display how to roll out Advantage app code on a new scratch org.
- You must deploy your project to Git and all branches should be created on a remote repository.
- A Jenkins file should be added to the project folder, containing the necessary settings for checking the project through the pipeline.
- Make sure that you have an available DevHub to create Scratch orgs.
1. Prepare a Jenkins file for pipeline configuration
1.1. In your Gitlab open your project, then select CI/CD -> Pipelines -> Run pipeline, then create a new pipeline.
1.2 Pipeline will be run automatically when you commit to any branch of the project. Then the validation process will be started.
2. Run the pipeline to check for errors in the project
2.1 First of all, at the “Build” stage, CI checks the project for the presence of all the metadata used. It is necessary that all objects, fields, classes, etc. are specified in. xml files. If you have passed this stage, it means that this project can be successfully deployed in scratch org.
2.2 Then your code needs to pass the code quality checking. This check provides the code with a static code analyzer for bad practices and unnecessary elements.
2.3 The last check is to run the unit tests. Tests are run as the standard user, without access to the application and all its components. Therefore, tests should be implemented using custom records of the User object and the System.runAs() method. The user must be assigned a permission set that grants access to all the necessary components of the application. If all pipeline checks have been passed, then the project is ready for deployment.
3. Push the project to Scratch org
3.1 Create a new Scratch org using the sfdx-project.json file. For correct project deployment, you need to add a parameter "namespace": "advantage" to this file.
3.2 Use a commanding force:source:push to push the project to Scratch org. If the validation by pipeline was successful, the project will be successfully deployed to the environment.
3.3 You need to configure your user to make this project available for use. Open Setup > Permission Sets, then select 'Advantage administrator' and add the assignment to your user.
Perform the same actions for the “Advantage user” permission set. Then you’ll be able to find the Advantage app in the list.
As a result of passing the verification, we got a ready-to-use project that can be quickly and easily deployed to any Scratch organization. After installing the project, it is very easy to configure it for use, without additional efforts on user profile and field-level security configuration. The user only needs to create or upload data via Data Loader. This greatly facilitates the project development process across divided organizations.