GitLab CI/CD
GitLab CI/CD is a tool for software development that uses various CI/CD methodologies. This section explains how you can run Qodana Docker images within GitLab CI/CD pipelines and covers the following cases:
Inspecting specific branches and merge requests
Forwarding inspection reports to Qodana Cloud
Exposing Qodana reports in the GitLab CI/CD user interface
Make sure that your project repository is accessible by GitLab CI/CD.
In the root directory of your project, save the .gitlab-ci.yml
file. This file will contain the pipeline configuration that will be used by GitLab CI/CD.
This is the basic pipeline configuration.
qodana:
image:
name: jetbrains/qodana-<linter>
entrypoint: [""]
cache:
- key: qodana-2023.1-$CI_DEFAULT_BRANCH-$CI_COMMIT_REF_SLUG
fallback_keys:
- qodana-2023.1-$CI_DEFAULT_BRANCH-
- qodana-2023.1-
paths:
- .qodana/cache
script:
- qodana --cache-dir=$CI_PROJECT_DIR/.qodana/cache
In this configuration, the image:name
keyword pulls the Qodana Docker image of your choice.
The cache
keyword configures GitLab caches to store the Qodana cache, so subsequent runs will be faster.
The script
keyword runs the qodana
command and enumerates the Qodana configuration options described in the Shell commands section.
Finally, artifacts
configures job artifacts that are uploaded, can be skipped if Qodana Cloud is used (described in the next steps).
Using the only
keyword, you can tell Qodana which branches to inspect. To inspect only the main
branch and incoming merge requests, you can use this configuration:
qodana:
only:
- main
- merge_requests
image:
name: jetbrains/qodana-<linter>
entrypoint: [""]
cache:
- key: qodana-2023.1-$CI_DEFAULT_BRANCH-$CI_COMMIT_REF_SLUG
fallback_keys:
- qodana-2023.1-$CI_DEFAULT_BRANCH-
- qodana-2023.1-
paths:
- .qodana/cache
script:
- qodana --results-dir=$CI_PROJECT_DIR/.qodana/results --cache-dir=$CI_PROJECT_DIR/.qodana/cache
Once the inspection step is complete, inspection reports can be forwarded to Qodana Cloud.
This configuration defines the QODANA_TOKEN
variable referring to the Qodana Cloud project token:
qodana:
image:
name: jetbrains/qodana-<linter>
entrypoint: [""]
cache:
- key: qodana-2023.1-$CI_DEFAULT_BRANCH-$CI_COMMIT_REF_SLUG
fallback_keys:
- qodana-2023.1-$CI_DEFAULT_BRANCH-
- qodana-2023.1-
paths:
- .qodana/cache
variables:
QODANA_TOKEN: $qodana_token
script:
- qodana --cache-dir=$CI_PROJECT_DIR/.qodana/cache
To make a report available in any given merge request without connecting to Qodana Cloud, you can use the artifacts
expose_as
keywords and change the path to the artifacts:
qodana:
image:
name: jetbrains/qodana-<linter>
entrypoint: [""]
cache:
- key: qodana-2023.1-$CI_DEFAULT_BRANCH-$CI_COMMIT_REF_SLUG
fallback_keys:
- qodana-2023.1-$CI_DEFAULT_BRANCH-
- qodana-2023.1-
paths:
- .qodana/cache
script:
- qodana --save-report --results-dir=$CI_PROJECT_DIR/.qodana/results
--cache-dir=$CI_PROJECT_DIR/.qodana/cache
artifacts:
paths:
- qodana/report/
expose_as: 'Qodana report'
Assuming that you have configured your pipeline in a similar manner, this is what it may look like:
Qodana report affiliated with a pipeline in a merge request
Available actions for a given exposed Qodana artifact
This configuration combines all approaches mentioned in this section.
qodana:
only:
- main
- merge_requests
image:
name: jetbrains/qodana-<linter>
entrypoint: [""]
variables:
QODANA_TOKEN: <your-project-token>
cache:
- key: qodana-2023.1-$CI_DEFAULT_BRANCH-$CI_COMMIT_REF_SLUG
fallback_keys:
- qodana-2023.1-$CI_DEFAULT_BRANCH-
- qodana-2023.1-
paths:
- .qodana/cache
script:
- qodana --cache-dir=$CI_PROJECT_DIR/.qodana/cache
Thanks for your feedback!