SonarQube Scanner 5.0.1.3006
SonarQube deployed with Docker behind Caddy
Problem:
I use Jenkins scripted pipeline with SonarQube Scanner to scan my project. The token currently used does not expire, but I got this log
ERROR Failed to query server version: GET https://mysonarqube.server/api/v2/analysis/version failed with HTTP 401. Please check the property sonar.token or the environment variable SONAR_TOKEN.
It seems that you are facing an authentication issue when using SonarQube with Jenkins. Here’s how you can proceed to resolve this problem:
Steps to Follow
Check SonarQube Configuration in Jenkins :
1. Go to Jenkins administration, then navigate to “Manage Jenkins” > “Configure System” .
2. Locate the SonarQube servers section and ensure the URL of your SonarQube server (SONAR_HOST_URL ) is correctly entered.
Verify Credentials :
3. In the same section, check the credentials associated with the SonarQube server. You should have a valid token configured.
4. If necessary, create a new token in the SonarQube interface and update the credentials in Jenkins.
Using withSonarQubeEnv() :
5. Make sure you are using the withSonarQubeEnv() method correctly by specifying the correct configuration name. For example, use:
1withSonarQubeEnv('sonarqube-staging') {
2 // your analysis code here
3}
Check Your Environment Variables :
6. Ensure that environment variables do not contain empty values for SONAR_TOKEN or other relevant parameters.
7. The SONARQUBE_SCANNER_PARAMS variable should include the token and must not be empty. Confirm that it is filled out correctly.
This indicates missing authentication, not invalid (or expired) authentication. So for some reason, your credentials are never making it to the scanner.