Sonnar Scanner doesent recognize arguments

Hello everyone,

SonarQube Version: Version 8.9.10
sonarqube-scanner Version: 2.8.2
Jenkins Version: 2.361.2

I’m trying to dynamically change the SonarQube branch name in my CI Pipeline. But it seem like the arguments that I pass to the scanner are ignored. At the Moment all the Scans are published on the default branch.
I have already tried to delete my properties File and set all arguments in the bash. But I get the following error:
ERROR: You must define the following mandatory properties for ‘Unknown’: sonar.projectKey
In my previous maven Project I could set the Branch name dynamically in the Jenkins File. Seems like in NPM it’s not possible to pass arguments to the Scanner. Can anyone help me?
That’s my actual properties File:

sonar.sources= .***
sonar.exclusions=**/*.spec.js, **/*.spec.ts, cypress**, **/*.conf.js, **/*.prod.js
sonar.coverage.exclusions=**/*.spec.ts, **/*module.ts

That’s my actual Jenkins File:

stage('SonarQube analysis') {
        steps {
            withSonarQubeEnv(credentialsId: '****',  installationName: '****') {
                echo "name is => ${env.BRANCH_NAME}"
                sh 'npm install sonar-scanner'
                sh "npm run sonar-scanner${env.BRANCH_NAME}"

When I set the in the File it works. But the name can’t be dynamically changed.

Hey there.

sonarqube-scanner - npm probably doesn’t support command line arguments being passed this way, but this npm package isn’t maintained or developed by SonarSource, so you’ll have to get in touch with the maintainer.

Out of curiosity – since you’re already using the SonarQube plugin for Jenkins… what benefits do you get from using npm run sonar-scanner over just running sonar-scanner?