Integrating SonarQube as a pull request approver on AWS CodeCommit

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    1.sonarQube version:9.9
    2.sonar-scanner version:sonar-scanner-4.7.0.2747-linux

  • how is SonarQube deployed: zip, Docker, Helm
    Source code deployment used in windows

  • what are you trying to achieve
    Integrating SonarQube as a pull request approver on AWS CodeCommit

  • what have you tried so far to achieve this
    1、MGT-workspace repository is created in aws codecommit, and the buildspec.yml configuration file is created in the library. The content of buildspec.yml is as follows:

1    version: 0.2
2	
3	phases:
4	  install:
5	    runtime-versions:
6	      nodejs: 10
7	    commands:
8	
9	      - wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.7.0.2747-linux.zip
10	      - export SONAR_SCANNER_VERSION=4.7.0.2747
11	      - export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux
12	      - curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip
13	      - unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
14	      - export PATH=$SONAR_SCANNER_HOME/bin:$PATH
15	      - export SONAR_SCANNER_OPTS="-server"
16	  pre_build:
17	    commands:
18	      - sonar-scanner -Dsonar.projectKey=goadmin -Dsonar.projectName=goadmin -Dsonar.sources=. -Dsonar.host.url=http://18.181.*.*:9000 -Dsonar.login=sqp_ec76ba88cacabd169b6aced86593760508******
19	      - sleep 5
20	      - curl https://sonarcloud.io/api/qualitygates/project_status?projectKey=0xriver_0xriver > analysis.json
21	      - cat analysis.json
22	  build:
23	    commands:
24	      - echo Building Project
25	      - echo Finished Building
26	
27	cache:
28	  paths:
29	    - "node_modules/**/*"

2、Click build in codebuild,The error message is as follows:
[Container] 2023/03/13 08:01:38 Running command sonar-scanner -Dsonar.projectKey=goadmin -Dsonar.projectName=goadmin -Dsonar.sources=. -Dsonar.host.url=http://18.181..:9000 -Dsonar.login=sqp_ec76ba88cacabd169b6aced865937605083208d5

/root/.sonar/sonar-scanner-4.7.0.2747-linux/bin/sonar-scanner: line 66: /root/.sonar/sonar-scanner-4.7.0.2747-linux/jre/bin/java: cannot execute binary file

3、I suspect that it is a problem with the java version. I try to add “yum install java-17” to buildspec.yml, but I also prompt that the yum command is not found

I think you’ll just need to recursively make the /.sonar/ directory executable, so that the embedded java executable can be excuted.