har17bar
har17bar

Reputation: 866

SonarQube: ERROR a branch analysis cannot have the pull request analysis parameter 'sonar.pullrequest.key'

I am running sonar-scanner with help of sonarqube.yml this code code snippet from there

  - name: Run sonarqube
    run: sonar-scanner
      -Dsonar.scm.provider=git
      -Dsonar.login=${{ secrets.SONARQUBE_TOKEN }}
      -Dsonar.pullrequest.key=${{ github.event.number }}
      -Dsonar.pullrequest.branch=${GITHUB_HEAD_REF#refs/heads/}
      -Dsonar.pullrequest.base=${GITHUB_BASE_REF#refs/heads/}
      -Dsonar.pullrequest.github.repository=${GITHUB_REPOSITORY}
      -Dsonar.pullrequest.github.endpoint=${GITHUB_API_URL}

Error after creating merge request enter image description here

  1. SonarQube Scanner version 4.2.0.1873
  2. SonarQube server version 9.0.1

i see in executing log that is remaining -Dsonar.pullrequest.key= to be equal to undefined

Run sonar-scanner -Dsonar.scm.provider=git -Dsonar.login=***  -Dsonar.pullrequest.key= -Dsonar.pullrequest.branch=${GITHUB_HEAD_REF#refs/heads/} -Dsonar.pullrequest.base=${GITHUB_BASE_REF#refs/heads/} -Dsonar.pullrequest.github.repository=${GITHUB_REPOSITORY} -Dsonar.pullrequest.github.endpoint=${GITHUB_API_URL}

Upvotes: 3

Views: 7992

Answers (1)

har17bar
har17bar

Reputation: 866

After merging branch to master it is commit and in that case ${{ github.event.number }} it's evaluating to null and it occures error so i suggest you to use in this case ${{github.sha}} even you can have condition

"-Dsonar.pullrequest.key=`if [ -z "${{github.event.number}}"  ]; then echo ${{github.sha}}; else echo ${{github.event.number}}; fi`"
          

Upvotes: 2

Related Questions