Hello, even I’m facing the same issue despite creating a global token (Administration > Security > Users > Generate new token, the user is administrator with groups sonar-administrators and sonar-users)
I’m basically trying to run a JS file which is as follows:
const scanner = require('@sonar/scan').default;
const path = require('path');
require('dotenv').config();
require('dotenv').config({ path: path.resolve(process.cwd(), '.env.local') });
const pkg = require('../package.json');
const PATH_TO_LCOV_FILE =
'./coverage/ut/lcov.info'; /* coverage report path relative to root */
const SOURCE = 'src';
const GIT_HOST = 'Github';
const ENCODING = 'utf-8';
const EXCLUSION_PATTERNS = [
'**/__tests__/**',
'**/__mocks__/**',
'**/*.styled.*',
];
const ORG_NAME = "ORG_ABC";
scanner(
{
serverUrl: process.env.SONAR_HOST_URL,
token: process.env.SONAR_TOKEN,
options: {
'sonar.host.url': process.env.SONAR_HOST_URL,
'sonar.token': process.env.SONAR_TOKEN,
'sonar.projectkey': pkg.name,
'sonar.organization': ORG_NAME,
'sonar.projectName': pkg.name,
'sonar.projectDescription': pkg.description,
'sonar.sources': SOURCE,
'sonar.tests': 'test',
'sonar.coverage.exclusions': EXCLUSION_PATTERNS.toString(),
'sonar.pullrequest.provider': GIT_HOST,
'sonar.pullrequest.github.repository': repoName,
'sonar.pullrequest.key':process.env.SONAR_CHANGE_ID /* pushed to env via pipeline */,
'sonar.pullrequest.branch': process.env.SONAR_CHANGE_BRANCH /* pushed to env via pipeline */,
'sonar.pullrequest.base':process.env.SONAR_CHANGE_TARGET /* pushed to env via pipeline */,
'sonar.branch.name':process.env.SONAR_BRANCH_NAME /* pushed to env via pipeline */,
},
},
() => process.exit()
);
On running the script, this is what I’m seeing on terminal:
node sonar/sonar-scanner.js – source=local
[INFO] Bootstrapper: Retrieving info from “package.json” file
[INFO] Bootstrapper: Platform: darwin arm64
[INFO] Bootstrapper: Server URL: http://localhost:8282
[INFO] Bootstrapper: Version: 4.3.2
[INFO] Bootstrapper: SonarQube server version: 25.12.0
[INFO] Bootstrapper: JRE provisioning is supported
[ERROR] Bootstrapper: An error occurred: AxiosError: Request failed with status code 401
On further debugging the cause for 401, I’m seeing that it is trying to hit ‘GET /api/v2/analysis/jres?os=darwin&arch=arm64 HTTP/1.1\r\n’ which is giving 401