Skip to main content
Teams+

GitLab Pipeline

To use GitLab CI/CD, you can either use the Gitlab pipeline editor under your repository

Gitlab pipeline

or you will need to create a .gitlab-ci.yml file in your repository.

GitLab uses a YAML file to define pipelines.

stages:
- test

include:
- template: Jobs/Code-Quality.gitlab-ci.yml

variables:
DCM_VERSION: "1.18.1-1" # Specify DCM version (e.g., "1.18.1-1")

dcm:
stage: test
image: dart:stable
before_script:
- apt-get update -qy
- apt-get install -y --no-install-recommends wget gnupg2
script:
- wget -qO- https://dcm.dev/pgp-key.public | gpg --dearmor -o /usr/share/keyrings/dcm.gpg
- echo 'deb [signed-by=/usr/share/keyrings/dcm.gpg arch=amd64] https://dcm.dev/debian stable main' | tee /etc/apt/sources.list.d/dart_stable.list
- apt-get update
- apt-get install dcm=$DCM_VERSION
- dcm run --analyze --unused-code --reporter=gitlab lib > gl-code-quality-report.json
#- dcm run --analyze --unused-code --reporter=console --ci-key="$DCM_CI_KEY" --email="$DCM_EMAIL" lib to # print in console and pass key and email
extends: code_quality
artifacts:
paths: [gl-code-quality-report.json]
  1. Image and Stages: We use dart:latest as the base image and define a single stage (analyze) where all jobs will run sequentially.

  2. Variables: Define any environment variables (FLUTTER_VERSION, DCM_VERSION) that you need for Flutter and DCM versions.

  3. Before Script: This section installs the necessary packages (wget, gnupg2) required for downloading and setting up Flutter and DCM.

  4. Install DCM: Adds the DCM repository's GPG key, sets up the repository source for DCM, updates package lists, and installs DCM using the specified version (DCM_VERSION).

  5. DCM Analyze: Runs the dcm run --analyze --unused-code command with required parameters (DCM_CI_KEY and DCM_EMAIL) to perform static code analysis on the lib directory. Note if the DCM_CI_KEY and DCM_EMAIL are available in an environment variable, they can be ignored by passing as parameters. DCM automatically detects these values from the environment.

  6. **Generate Reporter": you can create an artifacts to report back the code quality in GitLab by setting the report to --reporter=gitlab

  7. **Define artifacts": The artifacts.reports.codequality uses gl-code-quality-report.json to generate reports.

The result in the console (GitLab logs) will be:

Gitlab console

The result in the PR will be:

Gitlab PR

Setting Environment Variables in GitLab

Make sure you add your secrets to the GitLab setting under variables so that you can safely access sensitive information.

Gitlab variables

Notes

  • Customization: Adjust DCM_VERSION according to your project's requirements.

  • Security Considerations: Handle sensitive information (DCM_CI_KEY and DCM_EMAIL) securely using GitLab CI/CD environment variables or GitLab's CI/CD secret management.

  • Parallel Jobs: GitLab CI/CD allows parallel jobs within the same stage. If needed, you can split the DCM analysis into multiple jobs for different parts of your repository.