title: Error during SonarQube Scanner execution ERROR: "You must define the following mandatory properties for 'Unknown': sonar.projectKey"
body: <p>I am trying to execute sonarqube analysis through Jenkins declarative pipeline.</p>
  <p>When I execute sonarqube analysis using the below command in the jenkinfile, it works. But when I use the below function in jenkinsfile it gives me the error.But I want to use the withSonarQubeEnv() function for sonarqube analysis because I need to use the 'waitForQualityGate'.</p>
  <pre><code>withSonarQubeEnv('sonarqube')
  {
  }
  </code></pre>
  <pre><code>stage(&quot;Sonarqube Analysis&quot;) {
   steps {
    container('ibmcloudcli') { 
      echo &quot;Sonarqube Analysis.&quot;
      sh label: '', script: &quot;&quot;&quot;
        /opt/sonarscanner/sonar-scanner-3.2.0.1227-linux/bin/sonar-scanner   
       -Dsonar.host.url=XXXX                                       -Dsonar.login=XXXX
  -Dsonar.sources=/home/jenkins/agent/workspace/${JOB_NAME}/src -Dsonar.projectBaseDir=/home/jenkins/agent/workspace/${JOB_NAME}/src  -Dsonar.projectKey=${JOB_NAME} 
  -Dsonar.language=java 
  -Dsonar.java.binaries=/home/jenkins/agent/workspace/${JOB_NAME}/target -Dsonar.junit.reportPaths=/home/jenkins/agent/workspace/${JOB_NAME}/target/surefire-reports 
  -Dsonar.jacoco.reportPath=/home/jenkins/agent/workspace/${JOB_NAME}/target/site/jacoco/jacoco.xml 
     &quot;&quot;&quot;
  </code></pre>
  <p>SonarQube Scanner 3.2.0.1227 (installed in Jenkins slave pod)</p>
  <p>SonarQube server 7.9.3</p>
  <p>JENKINS_VERSION - 2.204.5</p>
  <p><strong>FYI</strong>:sonar-scanner.properties files does not contain any information
  everything is given through the command</p>
  <p>and running into the following issue:</p>
  <pre><code>Sonarqube Analysis.
  [Pipeline] withSonarQubeEnv
  Injecting SonarQube environment variables using the configuration: sonarqube
  [Pipeline] {
  [Pipeline] sh
  + /opt/sonarscanner/sonar-scanner-3.2.0.1227-linux/bin/sonar-scanner
  INFO: Scanner configuration file: /opt/sonarscanner/sonar-scanner-3.2.0.1227-linux/conf/sonar-scanner.properties
  INFO: Project root configuration file: NONE
  INFO: SonarQube Scanner 3.2.0.1227
  INFO: Java 1.8.0_121 Oracle Corporation (64-bit)
  INFO: Linux 4.15.0-106-generic amd64
  INFO: User cache: /root/.sonar/cache
  INFO: SonarQube server 7.9.3
  INFO: Default locale: &quot;en_US&quot;, source code encoding: &quot;US-ASCII&quot; (analysis is platform dependent)
  WARN: SonarScanner will require Java 11 to run starting in SonarQube 8.x
  INFO: Load global settings
  INFO: Load global settings (done) | time=119ms
  INFO: Server id: XXXX
  INFO: User cache: /root/.sonar/cache
  INFO: Load/download plugins
  INFO: Load plugins index
  INFO: Load plugins index (done) | time=72ms
  INFO: Load/download plugins (done) | time=373ms
  INFO: Process project properties
  INFO: ------------------------------------------------------------------------
  INFO: EXECUTION FAILURE
  INFO: ------------------------------------------------------------------------
  INFO: Total time: 2.205s
  INFO: Final Memory: 8M/393M
  INFO: ------------------------------------------------------------------------
  ERROR: Error during SonarQube Scanner execution
  ERROR: You must define the following mandatory properties for 'Unknown': sonar.projectKey
  ERROR: 
  ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
  [Pipeline] }
  WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succeeded?
  [Pipeline] // withSonarQubeEnv
  [Pipeline] }
  [Pipeline] // container
  [Pipeline] }
  </code></pre>
  <p>this is the Jenkinsfile &quot;sonarqube analysis&quot; stage</p>
  <pre><code>stage(&quot;Sonarqube Analysis&quot;) {
             steps {
               container('ibmcloudcli') {   
                  echo &quot;Sonarqube Analysis.&quot;
                  withSonarQubeEnv('sonarqube') {
                    sh '''/opt/sonarscanner/sonar-scanner-3.2.0.1227-linux/bin/sonar-scanner
                          -Dsonar.host.url=http://XXXX:9000
                          -Dsonar.login=XXXX
              -Dsonar.sources=/home/jenkins/agent/workspace/${JOB_NAME}/src 
              -Dsonar.projectBaseDir=/home/jenkins/agent/workspace/${JOB_NAME}/src  
              -Dsonar.projectKey=myfirstproject
              //-Dsonar.organization=default-organization
              -Dsonar.projectName=myfirstproject
              -Dsonar.projectVersion=1.0.0-alpha
              -Dsonar.language=java 
              -Dsonar.sourceEncoding=UTF-8
              -Dsonar.java.binaries=/home/jenkins/agent/workspace/${JOB_NAME}/target
              -Dsonar.junit.reportPaths=/home/jenkins/agent/workspace/${JOB_NAME}/target/surefire-reports 
              -Dsonar.jacoco.reportPath=/home/jenkins/agent/workspace/${JOB_NAME}/target/site/jacoco/jacoco.xml  
              -X
              '''
                  }           
           }    
             }
          }       
  
  </code></pre>