Build Failure: You're not authorized to run analysis

Hello everyone. I am building CI/CD pipeline using Jenkins file. A stage within the pipeline is to for SonarQube Analysis. Once the build gets to the stage, it keeps failing. The error message is stated below:

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar (default-cli) on project theITern: You're not authorized to run analysis. Please contact the project administrator. -> [Help 1].

Here is how I configured SonarQue within my Jenkins file:

     stage ('SonarQube Analysis') {
        steps {
              withSonarQubeEnv('sonar') {
                				dir('webapp'){
                 sh 'mvn -U clean install sonar:sonar'
                }
				
              }
            }
      }

I have added Jenkins user within my server to the sudoer group yet I can’t get beyond the state except I bypass SonarQube which I am not happy to do.

Please help.

Obtained Jenkinsfile from git https://adegokeobafemi-admin@bitbucket.org/adegokeobafemi/new.git
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/Project1
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
Selected Git installation does not exist. Using Default
The recommended git tool is: NONE
using credential git
 > /usr/bin/git rev-parse --resolve-git-dir /var/lib/jenkins/workspace/Project1/.git # timeout=10
Fetching changes from the remote Git repository
 > /usr/bin/git config remote.origin.url https://adegokeobafemi-admin@bitbucket.org/adegokeobafemi/new.git # timeout=10
Fetching upstream changes from https://adegokeobafemi-admin@bitbucket.org/adegokeobafemi/new.git
 > /usr/bin/git --version # timeout=10
 > git --version # 'git version 2.34.1'
using GIT_ASKPASS to set credentials BitBucket_Login
 > /usr/bin/git fetch --tags --force --progress -- https://adegokeobafemi-admin@bitbucket.org/adegokeobafemi/new.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > /usr/bin/git rev-parse refs/remotes/origin/master^{commit} # timeout=10
Checking out Revision 8cbe20ac8e3c7c895dd5dc4d791a41d3abbe3ee5 (refs/remotes/origin/master)
 > /usr/bin/git config core.sparsecheckout # timeout=10
 > /usr/bin/git checkout -f 8cbe20ac8e3c7c895dd5dc4d791a41d3abbe3ee5 # timeout=10
Commit message: "commit a8"
 > /usr/bin/git rev-list --no-walk 8555284c67a54c784c9fc1edd95312d73482a99b # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Tool Install)
[Pipeline] tool
[Pipeline] envVarsForTool
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Checkout SCM)
[Pipeline] tool
[Pipeline] envVarsForTool
[Pipeline] withEnv
[Pipeline] {
[Pipeline] checkout
Selected Git installation does not exist. Using Default
The recommended git tool is: NONE
using credential git
 > /usr/bin/git rev-parse --resolve-git-dir /var/lib/jenkins/workspace/Project1/.git # timeout=10
Fetching changes from the remote Git repository
 > /usr/bin/git config remote.origin.url https://adegokeobafemi-admin@bitbucket.org/adegokeobafemi/new.git # timeout=10
Fetching upstream changes from https://adegokeobafemi-admin@bitbucket.org/adegokeobafemi/new.git
 > /usr/bin/git --version # timeout=10
 > git --version # 'git version 2.34.1'
using GIT_ASKPASS to set credentials BitBucket_Login
 > /usr/bin/git fetch --tags --force --progress -- https://adegokeobafemi-admin@bitbucket.org/adegokeobafemi/new.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > /usr/bin/git rev-parse refs/remotes/origin/master^{commit} # timeout=10
Checking out Revision 8cbe20ac8e3c7c895dd5dc4d791a41d3abbe3ee5 (refs/remotes/origin/master)
 > /usr/bin/git config core.sparsecheckout # timeout=10
 > /usr/bin/git checkout -f 8cbe20ac8e3c7c895dd5dc4d791a41d3abbe3ee5 # timeout=10
Commit message: "commit a8"
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build)
[Pipeline] tool
[Pipeline] envVarsForTool
[Pipeline] withEnv
[Pipeline] {
[Pipeline] dir
Running in /var/lib/jenkins/workspace/Project1/webapp
[Pipeline] {
[Pipeline] sh
+ pwd
/var/lib/jenkins/workspace/Project1/webapp
[Pipeline] sh
+ ls -lah
total 52K
drwxr-xr-x 5 jenkins jenkins 4.0K Sep 25 00:26 .
drwxr-xr-x 7 jenkins jenkins 4.0K Sep 25 00:32 ..
-rw-r--r-- 1 jenkins jenkins 1.1K Aug 28 01:43 .classpath
-rw-r--r-- 1 jenkins jenkins   10 Aug 28 01:43 .gitignore
-rw-r--r-- 1 jenkins jenkins  558 Aug 28 01:43 .project
drwxr-xr-x 2 jenkins jenkins 4.0K Aug 28 01:43 .settings
-rw-r--r-- 1 jenkins jenkins 6.1K Sep 25 00:26 pom.xml
-rw-r--r-- 1 jenkins jenkins 6.0K Sep 12 01:12 pom.xml.old
-rw-r--r-- 1 jenkins jenkins 1.2K Aug 28 01:43 pom.xml44
drwxr-xr-x 3 jenkins jenkins 4.0K Aug 28 01:43 src
drwxr-xr-x 5 jenkins jenkins 4.0K Sep 25 00:26 target
[Pipeline] sh
+ mvn package
[INFO] Scanning for projects...
[WARNING] The project com.theITern:theITern:war:1.0-RELEASE uses prerequisites which is only intended for maven-plugin projects but not for non maven-plugin projects. For such purposes you should use the maven-enforcer-plugin. See https://maven.apache.org/enforcer/enforcer-rules/requireMavenVersion.html
[INFO] 
[INFO] -----------------------< com.theITern:theITern >------------------------
[INFO] Building theITerAPP 1.0-RELEASE
[INFO] --------------------------------[ war ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ theITern ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/Project1/webapp/src/main/resources
[INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/Project1/webapp/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ theITern ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ theITern ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/Project1/webapp/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ theITern ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.11:test (default-test) @ theITern ---
[INFO] No tests to run.
[INFO] Surefire report directory: /var/lib/jenkins/workspace/Project1/webapp/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-war-plugin:3.0.0:war (default-war) @ theITern ---
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.thoughtworks.xstream.core.util.Fields (file:/var/lib/jenkins/.m2/repository/com/thoughtworks/xstream/xstream/1.4.9/xstream-1.4.9.jar) to field java.util.TreeMap.comparator
WARNING: Please consider reporting this to the maintainers of com.thoughtworks.xstream.core.util.Fields
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] Packaging webapp
[INFO] Assembling webapp [theITern] in [/var/lib/jenkins/workspace/Project1/webapp/target/theITern-1.0-RELEASE]
[INFO] Processing war project
[INFO] Copying webapp resources [/var/lib/jenkins/workspace/Project1/webapp/src/main/webapp]
[INFO] Webapp assembled in [30 msecs]
[INFO] Building war: /var/lib/jenkins/workspace/Project1/webapp/target/theITern-1.0-RELEASE.war
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.089 s
[INFO] Finished at: 2022-09-25T00:32:23Z
[INFO] ------------------------------------------------------------------------
[Pipeline] }
[Pipeline] // dir
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (SonarQube Analysis)
[Pipeline] tool
[Pipeline] envVarsForTool
[Pipeline] withEnv
[Pipeline] {
[Pipeline] withSonarQubeEnv
Injecting SonarQube environment variables using the configuration: sonar
[Pipeline] {
[Pipeline] dir
Running in /var/lib/jenkins/workspace/Project1/webapp
[Pipeline] {
[Pipeline] sh
+ mvn -U clean install sonar:sonar
[INFO] Scanning for projects...
[WARNING] The project com.theITern:theITern:war:1.0-RELEASE uses prerequisites which is only intended for maven-plugin projects but not for non maven-plugin projects. For such purposes you should use the maven-enforcer-plugin. See https://maven.apache.org/enforcer/enforcer-rules/requireMavenVersion.html
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml
Progress (1): 2.7/21 kB
Progress (1): 5.5/21 kB
Progress (1): 8.2/21 kB
Progress (2): 8.2/21 kB | 2.7/14 kB
Progress (2): 8.2/21 kB | 5.5/14 kB
Progress (2): 8.2/21 kB | 8.2/14 kB
Progress (2): 8.2/21 kB | 11/14 kB 
Progress (2): 8.2/21 kB | 14/14 kB
Progress (2): 11/21 kB | 14/14 kB 
Progress (2): 14/21 kB | 14/14 kB
Progress (2): 16/21 kB | 14/14 kB
Progress (2): 19/21 kB | 14/14 kB
Progress (2): 21 kB | 14/14 kB   
Progress (2): 21 kB | 14 kB   
                           
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml (21 kB at 50 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml (14 kB at 33 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/sonar-maven-plugin/maven-metadata.xml
Progress (1): 1.3 kB
                    
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/sonar-maven-plugin/maven-metadata.xml (1.3 kB at 60 kB/s)
[WARNING] The artifact org.codehaus.mojo:sonar-maven-plugin:jar:3.9.1.2184 has been relocated to org.sonarsource.scanner.maven:sonar-maven-plugin:jar:3.9.1.2184: SonarQube plugin was moved to SonarSource organisation
[INFO] 
[INFO] -----------------------< com.theITern:theITern >------------------------
[INFO] Building theITerAPP 1.0-RELEASE
[INFO] --------------------------------[ war ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ theITern ---
[INFO] Deleting /var/lib/jenkins/workspace/Project1/webapp/target
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ theITern ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/Project1/webapp/src/main/resources
[INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/Project1/webapp/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ theITern ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ theITern ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/Project1/webapp/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ theITern ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.11:test (default-test) @ theITern ---
[INFO] No tests to run.
[INFO] Surefire report directory: /var/lib/jenkins/workspace/Project1/webapp/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-war-plugin:3.0.0:war (default-war) @ theITern ---
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.thoughtworks.xstream.core.util.Fields (file:/var/lib/jenkins/.m2/repository/com/thoughtworks/xstream/xstream/1.4.9/xstream-1.4.9.jar) to field java.util.TreeMap.comparator
WARNING: Please consider reporting this to the maintainers of com.thoughtworks.xstream.core.util.Fields
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] Packaging webapp
[INFO] Assembling webapp [theITern] in [/var/lib/jenkins/workspace/Project1/webapp/target/theITern-1.0-RELEASE]
[INFO] Processing war project
[INFO] Copying webapp resources [/var/lib/jenkins/workspace/Project1/webapp/src/main/webapp]
[INFO] Webapp assembled in [35 msecs]
[INFO] Building war: /var/lib/jenkins/workspace/Project1/webapp/target/theITern-1.0-RELEASE.war
[INFO] 
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ theITern ---
[INFO] Installing /var/lib/jenkins/workspace/Project1/webapp/target/theITern-1.0-RELEASE.war to /var/lib/jenkins/.m2/repository/com/theITern/theITern/1.0-RELEASE/theITern-1.0-RELEASE.war
[INFO] Installing /var/lib/jenkins/workspace/Project1/webapp/pom.xml to /var/lib/jenkins/.m2/repository/com/theITern/theITern/1.0-RELEASE/theITern-1.0-RELEASE.pom
[INFO] 
[INFO] -----------------------< com.theITern:theITern >------------------------
[INFO] Building theITerAPP 1.0-RELEASE
[INFO] --------------------------------[ war ]---------------------------------
[INFO] 
[INFO] --- sonar-maven-plugin:3.9.1.2184:sonar (default-cli) @ theITern ---
[INFO] User cache: /var/lib/jenkins/.sonar/cache
[INFO] SonarQube version: 9.5.0.56709
[INFO] Default locale: "en", source code encoding: "UTF-8"
[INFO] Load global settings
[INFO] Load global settings (done) | time=315ms
[INFO] Server id: A7EE8CF2-AYIOzNAfYKh8B97IK-fK
[INFO] User cache: /var/lib/jenkins/.sonar/cache
[INFO] Load/download plugins
[INFO] Load plugins index
[INFO] Load plugins index (done) | time=185ms
[INFO] Load/download plugins (done) | time=395ms
[INFO] Process project properties
[INFO] Process project properties (done) | time=14ms
[INFO] Execute project builders
[INFO] Execute project builders (done) | time=2ms
[INFO] Project key: com.theITern:theITern
[INFO] Base dir: /var/lib/jenkins/workspace/Project1/webapp
[INFO] Working dir: /var/lib/jenkins/workspace/Project1/webapp/target/sonar
[INFO] Load project settings for component key: 'com.theITern:theITern'
[INFO] Auto-configuring with CI 'Jenkins'
[INFO] Load quality profiles
[INFO] Load quality profiles (done) | time=253ms
[INFO] Load active rules
[INFO] Load active rules (done) | time=3683ms
[INFO] Load analysis cache
[INFO] Load analysis cache (404) | time=7ms
[INFO] Load project repositories
[INFO] Load project repositories (done) | time=11ms
[INFO] Indexing files...
[INFO] Project configuration:
[INFO] 3 files indexed
[INFO] 0 files ignored because of scm ignore settings
[INFO] Quality profile for jsp: Sonar way
[INFO] Quality profile for xml: Sonar way
[INFO] ------------- Run sensors on module theITerAPP
[INFO] Load metrics repository
[INFO] Load metrics repository (done) | time=63ms
[INFO] Sensor JaCoCo XML Report Importer [jacoco]
[INFO] 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
[INFO] No report imported, no coverage information will be imported by JaCoCo XML Report Importer
[INFO] Sensor JaCoCo XML Report Importer [jacoco] (done) | time=6ms
[INFO] Sensor CSS Rules [javascript]
[INFO] No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped.
[INFO] Sensor CSS Rules [javascript] (done) | time=1ms
[INFO] Sensor C# Project Type Information [csharp]
[INFO] Sensor C# Project Type Information [csharp] (done) | time=2ms
[INFO] Sensor C# Analysis Log [csharp]
[INFO] Sensor C# Analysis Log [csharp] (done) | time=29ms
[INFO] Sensor C# Properties [csharp]
[INFO] Sensor C# Properties [csharp] (done) | time=0ms
[INFO] Sensor HTML [web]
[INFO] Sensor HTML [web] (done) | time=124ms
[INFO] Sensor XML Sensor [xml]
[INFO] 2 source files to be analyzed
[INFO] 2/2 source files have been analyzed
[INFO] Sensor XML Sensor [xml] (done) | time=408ms
[INFO] Sensor Text Sensor [text]
[INFO] 3 source files to be analyzed
[INFO] 3/3 source files have been analyzed
[INFO] Sensor Text Sensor [text] (done) | time=10ms
[INFO] Sensor VB.NET Project Type Information [vbnet]
[INFO] Sensor VB.NET Project Type Information [vbnet] (done) | time=1ms
[INFO] Sensor VB.NET Analysis Log [vbnet]
[INFO] Sensor VB.NET Analysis Log [vbnet] (done) | time=27ms
[INFO] Sensor VB.NET Properties [vbnet]
[INFO] Sensor VB.NET Properties [vbnet] (done) | time=0ms
[INFO] ------------- Run sensors on project
[INFO] Sensor Analysis Warnings import [csharp]
[INFO] Sensor Analysis Warnings import [csharp] (done) | time=1ms
[INFO] Sensor Zero Coverage Sensor
[INFO] Sensor Zero Coverage Sensor (done) | time=0ms
[INFO] SCM Publisher SCM provider for this project is: git
[INFO] SCM Publisher 3 source files to be analyzed
[INFO] SCM Publisher 3/3 source files have been analyzed (done) | time=165ms
[INFO] CPD Executor Calculating CPD for 1 file
[INFO] CPD Executor CPD calculation finished (done) | time=8ms
[INFO] Analysis report generated in 85ms, dir size=129.6 kB
[INFO] Analysis report compressed in 23ms, zip size=21.2 kB
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  15.469 s
[INFO] Finished at: 2022-09-25T00:32:40Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar (default-cli) on project theITern: You're not authorized to run analysis. Please contact the project administrator. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Hey there

This means that the (SonarQube) user that is executing analysis does not have Execute Analysis permissions on the project.

In this case, it would be the user for which a token was defined in the sonar environment (withSonarQubeEnv(‘sonar’))