Integreer geautomatiseerde code quality checks in mijn GitLab CI pipeline
description
Met deze prompt kun je geautomatiseerde kwaliteitscontroles in je GitLab CI pipeline implementeren, waardoor je code betrouwbaarder en veiliger wordt. Het helpt fouten vroegtijdig te detecteren en verbetert de codekwaliteit zonder handmatige tussenkomst, wat efficiënter is dan traditionele benaderingen.
prompt
Help me met het opzetten van geautomatiseerde code quality checks binnen mijn GitLab CI pipeline. Mijn huidige configuratie: <voer je huidige GitLab CI YAML-configuratie in> Specifieke kwaliteitscriteri ...
try_prompt
generate_helper
disclaimerOnPageApi
tags
ai_answers
provider: openai
model: gpt-4.1-nano
Natuurlijk! Hieronder vind je een voorbeeld van een aangepaste `.gitlab-ci.yml` configuratie die ESLint en SonarQube integreert voor automatische code quality checks, met rapportage in JSON en een maximale tijdslimiet van 20 minuten per job.
```yaml
stages:
- build
- test
- quality
build_job:
stage: build
script:
- npm install
- npm run build
tags:
- docker # Indien je runners met docker gebruikt
timeout: 20m
test_job:
stage: test
script:
- npm test
tags:
- docker
timeout: 20m
eslint_job:
stage: quality
image: node:14 # of een andere geschikte Node.js versie
script:
- npm install eslint --save-dev
- npx eslint -f json -o eslint-report.json src/ # Pas de map aan indien nodig
artifacts:
reports:
junit: eslint-report.json
expire_in: 1 week
timeout: 20m
sonarqube:
stage: quality
image: sonarsource/sonar-scanner-cli:latest
variables:
SONAR_HOST_URL: "https://your-sonar-server"
SONAR_LOGIN: "$SONAR_TOKEN" # Voeg je token toe in CI/CD variabelen
script:
- sonar-scanner
-Dsonar.projectKey=your_project_key
-Dsonar.sources=src
-Dsonar.javascript.lcov.reportPaths=coverage/lcov.info
-Dsonar.report.export.path=sonar-report.json
artifacts:
reports:
json: sonar-report.json
expire_in: 1 week
timeout: 20m
```
**Belangrijke punten:**
- Voeg je SonarQube server-URL toe in `SONAR_HOST_URL`.
- Maak een CI/CD variabele aan genaamd `SONAR_TOKEN` met je authenticatietoken.
- Pas de paden aan (`src/`, `coverage/lcov.info`) volgens jouw projectstructuur.
- De ESLint rapportage wordt gegenereerd in JSON formaat; hetzelfde geldt voor SonarQube, die exporteert naar JSON.
- Iedere kwaliteitstest heeft een timeout van 20 minuten.
Wil je dat ik je help met het configureren van de SonarQube projectinstellingen of andere tools?
provider: deepseek
model: deepseek-chat
Hier is een aangepaste `.gitlab-ci.yml` configuratie met geautomatiseerde code quality checks:
```yaml
stages:
- build
- test
- quality
variables:
SONAR_SCANNER_VERSION: "4.8.0.2856"
ESLINT_OUTPUT: "eslint-report.json"
build_job:
stage: build
script:
- npm install
- npm run build
artifacts:
paths:
- dist/
expire_in: 1 hour
test_job:
stage: test
script:
- npm test
timeout: 20m
eslint_job:
stage: quality
script:
- npm install eslint --save-dev
- npx eslint . --format json --output-file $ESLINT_OUTPUT
artifacts:
paths:
- $ESLINT_OUTPUT
expire_in: 1 week
when: always
timeout: 20m
allow_failure: true
sonarqube_job:
stage: quality
image:
name: sonarsource/sonar-scanner-cli:$SONAR_SCANNER_VERSION
entrypoint: [""]
script:
- sonar-scanner
-Dsonar.projectKey=your_project_key
-Dsonar.sources=.
-Dsonar.host.url=${SONAR_HOST_URL}
-Dsonar.login=${SONAR_TOKEN}
-Dsonar.eslint.reportPaths=$ESLINT_OUTPUT
artifacts:
reports:
codequality: gl-sonar-report.json
timeout: 20m
allow_failure: true
dependencies:
- eslint_job
```
**Belangrijke stappen voor implementatie:**
1. **SonarQube variabelen instellen** in GitLab CI/CD settings:
- `SONAR_HOST_URL`: URL van je SonarQube instance
- `SONAR_TOKEN`: SonarQube authentication token
2. **ESLint configuratie** toevoegen aan je project:
```bash
npm install --save-dev eslint @eslint/js
npx eslint --init
```
3. **.eslintrc.json** aanpassen voor JSON output:
```json
{
"extends": "eslint:recommended",
"rules": {
// je custom rules
}
}
```
4. **.sonarscanner.properties** bestand toevoegen aan project root:
```properties
sonar.projectKey=your_project_key
sonar.projectName=Your Project Name
sonar.projectVersion=1.0
sonar.sources=src
sonar.exclusions=node_modules/**,dist/**
```
Deze configuratie voldoet aan je eisen: max 20 minuten per job, JSON rapportage, en integreert zowel ESLint als SonarQube in je pipeline.