[CI/CD study] - 10. Jenkins์ Sonarqube ์ฐ๋ํ๊ธฐ
[CI/CD study] - 6. Docker ์ Jenkins ์ค์นํ๊ธฐ
[CI/CD study] - 5. Docker ์ค์น [CI/CD study] - 4. EC2 ์ธ์คํด์ค Image ๋ง๋ค๊ธฐ [CI/CD study] - 3. AWS EC2 ์ธ์คํด์ค JAVA์ค์น [CI/CD study] - 2. SSH Client Tool์ ์ด์ฉํด EC2 ์ธ์คํด์ค ์ ์ [CI/CD study] -..
eun-jii.tistory.com
[CI/CD study] - 8. Docker ์ Sonarqube ์ค์นํ๊ธฐ
Docker Desktop ์ค์น Docker Hub ์ ์ํ ์ผ์ชฝ ์๋จ ๊ฒ์ ์ฐฝ์ " sonarqube " ๊ฒ์ ์๋ํ๋ธ ๊ณต์ ๊ณ์ ์ด๋ฏธ์ง์ ๋ช ๋ น์ด๊ฐ ๋์ด ํฐ๋ฏธ๋์ ๋ช ๋ น์ด โจ๏ธ docker pull sonarqube * ์ ๋ช ๋ น์ด๋ฅผ ์น๋ฉด ์๋์ผ๋ก ๋ง..
eun-jii.tistory.com
๐ฉโ๐ป ํ์๋ ์ง๊ธ ํ๋ก์ ํธ๋ฅผ ์งํํ๊ธฐ ์ํด CI/CD ์ฐ์ต์ค ์ธ ์ํฉ์ ๋๋ค.๐ฉโ๐ป
๐ Jenkins ์ Sonarqube๊ฐ ์ค์น ๋ ์ํ์์๋ง ์งํ๊ฐ๋ฅ ํฉ๋๋ค.

Jenkins ๊ด๋ฆฌ์์ ํ๋ฌ๊ทธ์ธ ๊ด๋ฆฌ ํด๋ฆญ

SonarQube Scanner for Jenkins ์ค์น
* SonarQube Scanner ๋ผ๊ณ ๋์๋ OK

๋ค์ Jenkins ๊ด๋ฆฌ์์ Global Tool Configuration ํด๋ฆญ

๋ด๋ฆฌ๋ค๋ณด๋ฉด SonarQube Scanner ์์ Add SonarQube Scanner ํด๋ฆญ

Name ์ง์ ํด์ฃผ๊ณ version ๋ ์ต์ ๋ฒ์ ์ผ๋ก ์ ํ โก ์ผ์ชฝ ํ๋จ SAVE
๐ฃ SonarQube ํ๋ก์ ํธ ์์ฑ

์๋ํ๋ธ ์คํ์์ผ์ฃผ๊ณ , Gitea๊ฐ ์๊ธฐ์ Manually ๋ก ์ ํ

Name ๊ณผ Key ์์ฑํ Set Up ํด๋ฆญ

์ฌ๊ธฐ๋ Gitea ๊ฐ ์์ด์ Other CI ํด๋ฆญ

Token name ์ง์ ํ No expiration (์ ํจ๊ธฐ๊ฐ์์) ์ค์ ํ Generate

Token ์์ฑ ์๋ฃ โก Continue ํด๋ฆญ

Others โก macOS ์ ํํ ๋์ค๋๊ฒ ํ์ธ (ํ์ธ๋ง ํ์ ๋ ๋ฉ๋๋น - ํฐ๋ฏธ๋์ ์์น์ ๋ ๋์ฌ..)

Jenkins ๋ก ๋์์ค์ ์ Jenkins ๊ด๋ฆฌ โก Security โก Manage Credentials ํด๋ฆญ

Stores scoped to Jenkins ์์ (global) โก Add credentials ํด๋ฆญ

๐ Kind = Secret text
๐ Scope = Global
๐ Secret = ์๋ํ๋ธ์์ ํ๋ก์ ํธ ์์ฑ์ ๋ง๋ ํ ํฐ
๐ ID ์ Description ์ ์์๋ก ์ง์
Create ํด๋ฆญ

Jenkins ๊ด๋ฆฌ โก ์์คํ ์ค์ ํด๋ฆญ

๋ด๋ฆฌ๋ค๋ณด๋ฉด SonarQube Servers ๊ฐ ๋์ค๊ณ Add SonarQube ํด๋ฆญ

๐ Name = ์์์ง์
๐ Server URL = ๋ณธ์ธ ์๋ํ๋ธ URL
* 9000 ํฌํธ ๋ค์ / ๊ฐ ๋ถ์ผ๋ฉด ์๋จ
๐ Server authentication token = Credentials ์์ ์์ฑํ ํ ํฐ (์ด๋ฏธ ๋ง๋ค์๊ธฐ ๋๋ฌธ์ ์ ํํ๋ฉด ๋จ)
์ผ์ชฝ ํ๋จ SAVE ํด๋ฆญ
๐ฃ Jenkinsfile ๋ด์์ SonarQube๋ฅผ ์คํํ๋ ์คํฌ๋ฆฝํธ ์์ฑ

pipeline {
agent any
tools {nodejs "16.10.0"}
stages {
stage("sonarqube") {
steps{
script{
def scannerHome = tool 'Sonarqube-Scanner';
withSonarQubeEnv(credentialsId:"sonar-Token",installationName:'sonarqube-test') {
sh "${scannerHome}/bin/sonar-scanner"
}
}
}
}
}
}
Jenkinsfile ์ Pipeline Code ์์ฑ
๐ CredentialsID = Jenkins ์์ Credentials ์์ฑํ ๋ ๋ง๋ค์๋ name
๐ installationName = Jenkins ์์ SonarQube Server ์ฐ๋์ ๋ง๋ค์๋ name

Jenkinsfile ๊ณผ ๊ฐ์ ํด๋ ๋ด์ sonar-project.properties ํ์ผ ์์ฑ

# must be unique in a given SonarQube instance
sonar.projectKey=my:project ๐ my:project ๋์ ๋ณธ์ธ ์๋ํ๋ธ ํ๋ก์ ํธ ์ด๋ฆ ์ ๊ธฐ ๐
# --- optional properties ---
# defaults to project key
#sonar.projectName=My project
# defaults to 'not provided'
#sonar.projectVersion=1.0
# Path is relative to the sonar-project.properties file. Defaults to .
#sonar.sources=.
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
์์ฑํ Gitea์ push ํด๋๊ธฐ

Jenkins Plugin ๊ด๋ฆฌ์์ NodeJS ์ค์นํ๊ธฐ ( VSCODE npm build์ ํ์ํจ )

Jenkins ๊ด๋ฆฌ โก Global Tool Configuration ์ ๋งจ๋ฐ NodeJS ์ค์ ํด์ฃผ๊ธฐ
๐
๐ ์ ํจ์ค์์ ์๋ํ๋ธ๋ฅผ ๋น๋ํ๊ฒ๋๋ฉด EC2 ๋ฉ๋ชจ๋ฆฌ ์ฉ๋์ ๋ถ์กฑ์ผ๋ก ๋น๋๊ฐ ๋ฉ์ถ๊ฒ ๋ ์ ์์
๊ทธ๋์ ๋ฏธ๋ฆฌ ์ค์๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ค์ ํด๋๋ฉด ์ด๋ฅผ ๋ฐฉ์งํ ์ ์์
SSH Docker ํฐ๋ฏธ๋์ ๋ค์ด๊ฐ์ ๋ค์๊ณผ ๊ฐ์ด ์์ฑํด์ฃผ๊ธฐ
โจ๏ธ sudo dd if=/dev/zero of=/mnt/swapfile bs=1M count=2048
โจ๏ธ sudo mkswap /mnt/swapfile
โจ๏ธ sudo swapon /mnt/swapfile
[https://dundung.tistory.com/284]
๋ง์ฝ sudo not command ์๋ฌ๊ฐ ๋์จ๋ค๋ฉด
โจ๏ธ apt-get install sudo -y
๋ฅผ ๋จผ์ ์คํํ๊ณ ๋ค์ ์งํํ๊ธฐ
๐

Build ์ฑ๊ณต โญ๏ธ
๋์์ฃผ์ ๋ถ โค๏ธ :