Set Up NDepend Reporting in GitLab CI/CD
Send us an email at devops@ndepend.com for product and sales questions.
Integrating NDepend Reporting in GitLab CI/CD
2. Configure GitLab CI/CD Pipeline
3. Monitor Quality Gates Using Exit Codes
Integrating NDepend Reporting in GitLab CI/CD
Follow these steps to integrate NDepend into your GitLab CI/CD pipeline for .NET code analysis and reporting:
Prerequisites
- NDepend Console: You need to have the NDepend redistributable unzipped with access to either
NDepend.Console.exe
(for Windows) orNDepend.Console.MultiOS.exe
(for Linux/macOS/Windows) available in your GitLab pipeline environment. Make sure that the executable is properly referenced in your GitLab pipeline configuration file (.gitlab-ci.yml
). See the documentation for NDepend.Console here. - .NET Solution: Ensure that you have a .NET solution that you want to analyze using NDepend.
1. Create an NDepend Project
You must create an NDepend project that references your .NET solution. This can be done using either:
- The UI
VisualNDepend.exe
(for Windows), or - The
Visual Studio NDepend exetnsion
(for Windows), or NDepend.Console.MultiOS.exe
(for Linux/macOS/Windows) Follow the guide in the NDepend Documentation for detailed instructions.
2. Configure GitLab CI/CD Pipeline
Edit your GitLab pipeline configuration file (.gitlab-ci.yml
) to include a job that runs the NDepend analysis. Specify the path to the NDepend Console executable and your NDepend project file (.ndproj
).
stages:
- build
- analyze
build:
script:
- dotnet build
analyze:
script:
- /path/to/NDepend.Console.exe /path/to/your/project.ndproj
- if [ $? -ne 0 ]; then exit 1; fi
artifacts:
paths:
- NDependOut/NDependReport.html
- NDependOut/NDependReportFiles/
In this example, replace /path/to/NDepend.Console.exe
with the actual path to the NDepend.Console.exe
(or NDepend.Console.MultiOS.exe
), and /path/to/your/project.ndproj
with the correct path to your NDepend project file.
Refer to the NDepend.Console documentation to eventually customize the command line options.
3. Monitor Quality Gates Using Exit Codes
NDepend returns an exit code to indicate whether the quality gates were passed or failed. If the quality gates fail, the job will return a non-zero exit code, causing the pipeline to fail.
You can check the exit code to determine whether the pipeline should fail if quality gates are not met:
analyze:
script:
- /path/to/NDepend.Console.exe /path/to/your/project.ndproj
- if [ $? -ne 0 ]; then exit 1; fi
This ensures that the GitLab pipeline stops if NDepend fails the quality gate checks.
Refer to the Quality Gates documentation for more details abotu this topic.
4. Collect and Share the Reports
After the analysis completes, NDepend will generate an HTML report along with related assets. These files will typically be located in the NDependOut
directory of your project.
To make these reports accessible to your team, upload them as GitLab artifacts in your pipeline configuration:
analyze:
script:
- /path/to/NDepend.Console.exe /path/to/your/project.ndproj
artifacts:
paths:
- NDependOut/NDependReport.html
- NDependOut/NDependReportFiles/
The following report files will be generated:
.\NDependOut\NDependReport.html
.\NDependOut\NDependReportFiles\
(directory containing additional report files and child directories as well)
These files will be available as downloadable artifacts after the pipeline execution completes.
5. Review Sample Reports
For reference, you can view sample NDepend reports to understand the structure and content of the generated analysis: