๐Ÿค ์€์ง€log ๐Ÿค

[CI/CD study] - 10. Jenkins์™€ Sonarqube ์—ฐ๋™ํ•˜๊ธฐ ๋ณธ๋ฌธ

๐Ÿ’š DevOps

[CI/CD study] - 10. Jenkins์™€ Sonarqube ์—ฐ๋™ํ•˜๊ธฐ

Eun_zii 2022. 10. 14. 12:16
 

[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 ์„ฑ๊ณต โญ๏ธ

 

 

 

 

 

 

 

๋„์›€์ฃผ์‹ ๋ถ„ โค๏ธ :

https://m.blog.naver.com/suyoungpk/222897192890

https://code00.tistory.com/135

728x90