To run GitLab's Code Quality checks offline, you'll need to ensure all dependencies are available locally. Here's a step-by-step guide based on GitLab's documentation and best practices:
Steps to Run GitLab Code Quality Offline
1. Understand the Dependencies
GitLab's Code Quality uses:
- Code Climate Engines (for analysis)
- Docker (to run the engines)
- GitLab Runner (to execute the job)
Since these engines are typically pulled from Docker Hub, you need to:
- Download the required Docker images in advance.
- Configure GitLab Runner to use local images.
2. Download Required Docker Images
The main image used is:
docker pull codeclimate/codeclimate
(Check the latest version in GitLab's Code Quality docs.)
If you're using other engines (e.g., structure, duplication), download them too:
docker pull codeclimate/codeclimate-structure
docker pull codeclimate/codeclimate-duplication
3. Save Docker Images for Offline Use
Export the images to .tar files:
docker save codeclimate/codeclimate -o codeclimate.tar
docker save codeclimate/codeclimate-structure -o codeclimate-structure.tar
Transfer these files to your offline machine and load them:
docker load -i codeclimate.tar
docker load -i codeclimate-structure.tar
4. Configure GitLab Runner to Use Local Images
Modify your .gitlab-ci.yml to explicitly use the local images:
code_quality:
image: codeclimate/codeclimate:latest # Ensure this matches your local image
script:
- /codeclimate/codeclimate analyze -f json > codeclimate.json
artifacts:
reports:
codequality: codeclimate.json
5. Run GitLab Runner in Offline Mode
Ensure your GitLab Runner is configured to work offline:
6. Test the Setup
Run a pipeline manually to verify it works:
gitlab-runner exec docker code_quality
Alternative: Use a Local Code Quality Tool
If Docker is not an option, you can:
- Use a local static analysis tool (e.g.,
SonarQube, PMD, Checkstyle).
- Generate a compatible JSON report (GitLab expects Code Climate format).
- Upload the report as an artifact in
.gitlab-ci.yml.
Example with PMD:
code_quality:
script:
- ./run_pmd.sh > codeclimate.json # Your script to generate the report
artifacts:
reports:
codequality: codeclimate.json
Verification
- Check GitLab’s Code Quality documentation for updates.
- Ensure all required engines are available locally.
- Test in an isolated environment before full offline deployment.
This method ensures Code Quality runs without internet access while maintaining compatibility with GitLab’s expectations.