2023년 3월 10일 금요일

SonarQube Installation ( on Ubuntu )

 $ sudo apt update




$ sudo apt -y install apt-transport-https ca-certificates curl gnupg-agent software-properties-common


$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -






$ wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-9.8.0.63668.zip


$ unzip sonarqube-9.8.0.63668.zip


$ sudo groupadd sonar


$ sudo useradd -c "SonarQube - User" -d /home/shlee/sonarqube/ -g sonar sonar


# $ sudo chown -R sonar:sonar /home/shlee/sonarqube/


$ sudo chown -R shlee:shlee /home/shlee/sonarqube/




$ /home/shlee/sonarqube/bin/linux-x86-64/sonar.sh start


$ /home/shlee/sonarqube/bin/linux-x86-64/sonar.sh stop




$ curl localhost:9000 [admin/admin and change password]




[SonarQube Setup in gitlab / SonarQube]


1) create gitlab Impersonation Token in Gitlab


2) create gitlab project and insert gitlab Token in sonarqube 


3) create credential for "admin" account in sonarqube 


   and copy credential, paste to jenkins new credentials






[SonarQube Setup In jenkins]


Install GitLab plugin for Jenkins - version 1.5.13 or later


Install SonarQube Scanner plugin for Jenkins - version 2.11 or later




setting for integrating cicd


setting for sonarqube server 




[Jenkinsfile]


  withSonarQubeEnv('sonarqube_rookie01') {


                sh "mvn clean verify sonar:sonar -Dsonar.projectKey=<프로젝트 키>"


              }




sonarqube_rookie01 <- ID for sonarQube Server Setting


<프로젝트 키> <-- project key in sonarqube


-----




(1) Docker Push in Jenkinsfile


 docker.withRegistry('<Docker Registry URL>', '<Credential defined in Jenkins Credentials>') {


     dockerImage.push('<Tag>')


 }




ex>


 docker.withRegistry('http://localhost:7890/repository/docker-local-registry/', 'docker_credential') {


      dockerImage.push('latest')


 }




(2) Integrate Sonar with Jenkins


 withSonarQubeEnv('<Name of Jenkins SonarQube Server Settings>') {


      sh "mvn clean verify <Goal for SonarQube (default :  'sonar:sonar' )> -Dsonar.projectKey=<ProjectKey generated by SonarQube Server>"


 }


[업데이트 2026-10]

  • SonarQube 9.8은 오래된 버전이다. 현재 Community Build는 Java 17 또는 21이 필요하고, 압축을 푸는 디렉터리 이름이 숫자로 시작하면 안 된다.
  • 첫 로그인은 admin/admin이고, 로그인하면 바로 비밀번호를 바꿔준다.
  • 맨 위의 Docker apt 키 등록 명령은 SonarQube 설치와 직접 관련이 없어 보인다. 복사하다 섞인 것 같으니 따라 하지 않아도 된다.
  • 스캐너(SonarScanner)의 Java 요구 버전도 올라가고 있다. 2026년 7월부터 Community Build용 스캐너는 Java 21만 지원하고, JRE 자동 프로비저닝이 켜져 있으면 따로 신경 쓰지 않아도 된다.
  • 프로젝트 키는 노출을 피하려고 <프로젝트 키>로 바꿔 두었다.

댓글 없음:

댓글 쓰기