Cant Connect Eslint to sonarcloud

Me and my group are trying to integrate ESlint into Sonarcloud with Gitlab pipeline, but we receive and error and pipeline fails with exit code 1.

The content of the sonar-properties file is:

sonar.projectKey=**
sonar.organization=**
sonar.testExecutionReportPaths=reports/test-reporter.xml
sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.eslint.reportPaths=reports/eslint-report.json
sonar.sources=src
sonar.tests=src
sonar.test.inclusions=src//*.spec.ts,src//.test.ts,src/app/test.ts,src/app/.spec.ts

The content of the .gitlab-ci.yml file :

variables:
SONAR_USER_HOME: “${CI_PROJECT_DIR}/.sonar” # Defines the location of the analysis task cache
GIT_DEPTH: “0” # Tells git to fetch all the branches of the project, required by the analysis task
sonarcloud-check:
image:
name: sonarsource/sonar-scanner-cli:latest
entrypoint: [""]
cache:
key: “${CI_JOB_NAME}”
paths:
- .sonar/cache
script:
- npm install
- npm test – --coverage --testResultsProcessor=jest-sonar-reporter
- npx eslint -f json -o reports/eslint-report.json src
- cat reports/eslint-report.json
- sonar-scanner -X

only:
- merge_requests
- master
- develop
- main
- testbranch

How can we solve this issue ?

Hello @Goumalicious , welcome to the Community! Thank you so much for your patience. I reviewed your .gitlab-ci.yml file and the problem is that your eslint command comes back with an error in case some linting problem has been found in your code. This error makes the whole pipeline fail as a result.

I think what you would prefer to have is to generate the eslint report in any case and continue with the pipeline. I suggest you try to use add || true at the end of your eslint command or any other solution that fits you in order to continue with the pipeline execution.

It would be something like this:
- npx eslint -f json -o reports/eslint-report.json src || true

Please, let me know if there’s anything else we can help you with.

Best regards

I prefer the continue-on-error flag, which I find to be a little more self-explanatory than the || true condition. (It’s available at both the steps and the job levels.)