[CI/CD] Jenkins Trigger ์ •๋ณด Discord๋กœ ๋ณด๋‚ด๊ธฐ

2023. 6. 1. 21:04ใ†System ์ž‘์—…์‹ค/DevOps

728x90
๋ฐ˜์‘ํ˜•

 

 

 

 

 

 

์  ํ‚จ์Šค ๋งˆ์Šคํ„ฐ

COUPANG

www.coupang.com

"์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์Šต๋‹ˆ๋‹ค."

 

 

 

 




๐Ÿ—‚ ๋ชฉ์ฐจ

โš ๏ธ ์•„๋ž˜ ๋ชฉ์ฐจ ์ค‘ ๋ช‡๋ช‡๊ฐœ์˜ ๋งํฌ๊ฐ€ ๊ฑธ๋ฆฌ์ง€ ์•Š๋Š” ๋ฌธ์ œ๋กœ ๊ธ€ ๋งจ ํ•˜๋‹จ์— ๋‹ค์Œ ๊ธ€๋กœ ์ด๋™ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด ๋‘์—ˆ์Šต๋‹ˆ๋‹ค.

โœ… [CI/CD] Jenkins์™€ Gitea ์—ฐ๋™
โœ… [CI/CD] Jenkins Trigger ์ •๋ณด Discord๋กœ ๋ณด๋‚ด๊ธฐ
โœ… [CI/CD] ์ •์  ์ฝ”๋“œ ๋ถ„์„ ํˆด SonarQube์™€ Jenkins ์—ฐ๋™
โœ… [CI/CD] SonarQube๋ฅผ ํ†ตํ•ด Code Convention ์ ์šฉ
โœ… [DevOps] JAVA Gradle JaCoCo (Code coverage) ์„ค์ •ํ•˜๊ธฐ 
โœ… [DevOps] JAVA Gradle JaCoCo (Code coverage) ์„ค์ •ํ•˜๊ธฐ (์ถ”๊ฐ€)(https://junyharang.tistory.com/392)

โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘  Application Linuxt(Ubuntu)์— SSH๋ฅผ ์ด์šฉํ•œ ํŒŒ์ผ ์ „์†ก
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ก Create Docker Image And BackUp
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ข Application Server Docker Job (โ‘  Application ๋„์ปค ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธ)
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ข Application Server Docker Job (โ‘ก Application Docker Run)(https://junyharang.tistory.com/406)
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ข Application Server Docker Job (โ‘ข Application Docker Health Check)
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ฃ NGINX Server Docker Job (โ‘  NGINX ๊ฐ ์ข… ์„ค์ •) 
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ฃ NGINX Server Docker Job (โ‘ก NGINX Docker ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธ) 
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ฃ NGINX Server Docker Job (โ‘ข NGINX Docker Run & Health Check)
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ฃ NGINX Server Docker Job (โ‘ข NGINX ์žฌ ์„ค์ •)



๐Ÿค” ๋‚ด๊ฐ€ ๋งŒ๋‚œ ๋ฌธ์ œ

โ›”๏ธ [Jenkins] java.lang.OutOfMemoryError: Java heap space

 

 

 

 

 

 

๐Ÿš€ Jenkins Trigger ์ •๋ณด Discord๋กœ ๋ณด๋‚ด๊ธฐ

    ๐Ÿ”ฝ  ๊ฐœ์š”

        ๐Ÿ“ฆ ๊ตฌ์„ฑ๋„

CI/CD ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ ๊ตฌ์„ฑ๋„

 

 

 

 

 

 

deploy Directory Path

 

 

 

        ๐Ÿ“ฆ ์†Œ๊ฐœ

์—ฌ๋Ÿฌ ๊ฐœ๋ฐœ์ž๋“ค์ด ์ž‘์—…์„ ํ•  ๋•Œ, Dev Branch๋‚˜, Master Branch์— Merge๊ฐ€ ๋˜์–ด CI/CD๊ฐ€ ์ง„ํ–‰๋˜๊ฒŒ ๋˜๋ฉด ์–ด๋–ค ๋‹จ๊ณ„๋ฅผ ๊ฑฐ์ณ ์–ด๋–ป๊ฒŒ ์ง„ํ–‰๋˜๊ณ  ์žˆ๋Š”์ง€ Jenkins Web Service๋ฅผ ๋ณด์ง€ ์•Š๋Š”๋‹ค๋ฉด ํ™•์ธํ•  ์ˆ˜๊ฐ€ ์—†์–ด์š”.

ํ•˜์ง€๋งŒ, Jenkins์™€ ๊ฐ™์€ ์ค‘์š”ํ•œ Service๋Š” ๊ผญ ํ•„์š”ํ•œ ์‚ฌ๋žŒ ์™ธ์—๋Š” ์ ‘๊ทผ์ด ๋ถˆ๊ฐ€ํ•ด์•ผ ํ•  ๊ฒƒ์ด๊ณ , ์ ‘๊ทผ์ด ๋ถˆ๊ฐ€ํ•œ ์‚ฌ๋žŒ๋“ค๋„ CI/CD ์ง„ํ–‰ ์‚ฌํ•ญ์ด ๊ถ๊ธˆํ•  ๊ฒƒ์ด๊ณ , ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•˜๋‹ค๊ณ  ํ•˜๋”๋ผ๋„ ๊ตณ์ด Web Service๋ฅผ ๋ณด์ง€ ์•Š๊ณ , ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค๋ฉด ๋” ์ข‹์„๊ฑฐ์—์š”.

Jenkins Trigger๋ฅผ ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” SNS๋Š” Slack๋„ ์žˆ์ง€๋งŒ, ์ฃผ๋‹ˆ๋Š” Discord๋ฅผ ํ†ตํ•ด ๋ฐ›๋Š” ๊ฒƒ์„ ํ•ด๋ณด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

ํ˜„์žฌ ์ฃผ๋‹ˆ๊ฐ€ ํ•˜๊ณ  ์žˆ๋Š” Project๋Š” Discord Bot์„ ํ†ตํ•ด ๋งŽ์€ ๊ฒƒ๋“ค์„ ํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด์—์š”.

 

๋ฐ˜์‘ํ˜•

 

    ๐Ÿ”ฝ  Jenkins

        ๐Ÿ“ฆ ์„ค์ •(Configure)

์ตœ์ดˆ Discord์™€ ์—ฐ๊ฒฐ์„ ์œ„ํ•ด Jenkins PlugIn์„ ์„ค์น˜ํ•ด ์ฃผ์–ด์•ผ ํ•ด์š”.

Jenkins ๊ด€๋ฆฌ -> PlugIn Manager


์œ„์™€ ๊ฐ™์ด Discord Notifier PlugIn์„ ์„ค์น˜ํ•ด ์ค๋‹ˆ๋‹ค.


์ฐธ๊ณ ๋กœ ํ˜„์žฌ ์ฃผ๋‹ˆ๊ฐ€ ๊ตฌ์„ฑํ•œ Jenkins Job์€ MultiBranch Pipeline Item์ด๊ธฐ ๋•Œ๋ฌธ์—
๋นŒ๋“œ ํ›„ ๊ธฐ๋Šฅ Option์ด ์กด์žฌํ•˜์ง€ ์•Š์•„์š”.

๊ทธ๋ž˜์„œ ์ฃผ๋‹ˆ๋Š” pipeline Script๋ฅผ ์ด์šฉํ•ด์„œ ์ž‘์„ฑํ•ด ์ค„๊ฑฐ์—์š”.

 

728x90

 

    ๐Ÿ”ฝ  Discord

        ๐Ÿ“ฆ ์„ค์ •(Configure)


์ตœ์ดˆ ์œ„์™€ ๊ฐ™์ด ์ฑ„๋„์„ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด ์ค„๊ฒŒ์š”.


๋Œ€์ƒ ์ฑ„๋„ ์„ค์ • -> ์—ฐ๋™


๊ทธ๋Ÿฐ ๋’ค ํ•ด๋‹น ์ฑ„๋„ ์„ค์ •์ฐฝ์œผ๋กœ ๋“ค์–ด์™€ ์œ„์™€ ๊ฐ™์ด ์—ฐ๋™์œผ๋กœ ์ด๋™ํ•ด ์ค๋‹ˆ๋‹ค.

์ด ๊ณณ์—์„œ Webhook ๋งŒ๋“ค๊ธฐ๋ฅผ ์„ ํƒํ•ด ์ค„๊ฒŒ์š”.



์ด๋ ‡๊ฒŒ ์„ค์ •์„ ํ•˜๊ณ , ์›นํ›„ํฌ URL ๋ณต์‚ฌ๋ฅผ ๋ˆŒ๋Ÿฌ ๋งŒ๋“ค์–ด์ง„ URL์„ ํš๋“ํ•˜๊ณ , ๋ณ€๊ฒฝ์‚ฌํ•ญ ์ €์žฅํ•˜๊ธฐ๋ฅผ ๋ˆŒ๋Ÿฌ์ค„๊ฒŒ์š”.


jenkinsfile


๊ทธ๋Ÿฐ ๋’ค jenkins file์— Build๊ฐ€ ์„ฑ๊ณตํ–ˆ์„ ๋•Œ์™€ ์‹คํŒจํ–ˆ์„ ๋•Œ ์•Œ๋ฆผ์„ ๋ฐ›๊ธฐ ์œ„ํ•œ ๋‚ด์šฉ์„ ์ถ”๊ฐ€ํ•ด ์ฃผ์—ˆ์–ด์š”.

์œ„์˜ link ๋ถ€๋ถ„ Discord ์•Œ๋ฆผ Message์— Title ๋ฌธ์ž์—ด์— ํ•˜์ดํผ๋งํฌ ์ฒ˜๋ฆฌ๋ฅผ ํ•˜์—ฌ ํด๋ฆญํ•˜๋ฉด
Jenkins๋กœ ์ด๋™ํ•  ์ˆ˜ ์žˆ๊ฒŒ ์ฒ˜๋ฆฌํ•ด์ฃผ๊ธฐ ์œ„ํ•จ์ด์—์š”. 

webhook URL์—๋Š” Discord์—์„œ ๋ฐ›์€ URL์„ ๋„ฃ์–ด์ฃผ๋ฉด ๋˜์š”.

์ด๋ ‡๊ฒŒ ํ•˜๊ณ , Gitea๋กœ Push๋ฅผ ํ•˜๊ฒŒ ๋˜๋ฉด Jenkins์— Trigger๊ฐ€ ๊ฑธ๋ฆฌ๊ฒŒ ๋˜๊ณ ,
์ž‘์—…์ด ๋๋‚˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด Discord์— ์•Œ๋ฆผ์ด ์˜ค๋Š” ๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.




ํ•˜์ง€๋งŒ, ์œ„์™€ ๊ฐ™์ด jenkinsfile์— Discord Webhook ์ฃผ์†Œ๋ฅผ Hard Codingํ•˜๋Š” ๊ฑด ์ข‹์€ ๋ฐฉ๋ฒ•์ด ์•„๋‹ˆ์—์š”.

๊ทธ๋ž˜์„œ Jenkins Credentials๋ฅผ ์ด์šฉํ•ด์„œ ์•ˆ์ „ํ•˜๊ฒŒ ํ•ด๋‹น ๊ฐ’์„ ๋ณด๊ด€ํ•˜๊ณ , ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ๋„๋ก ํ•ด ๋ณผ๊ฒŒ์š”.


Jenkins ๊ด€๋ฆฌ -> Credentials -> System -> Global credentials (unrestricted)


์ด ๊ณณ์—์„œ Add Credentials์„ ๋ˆŒ๋Ÿฌ ์ค„๊ฒŒ์š”.



์ตœ์ดˆ kind๋Š” Secret text๋กœ ์„ ํƒํ•ด ์ฃผ์„ธ์š”.



secret ๋ถ€๋ถ„์—๋Š” Discord Webhook URL์„ ์ž…๋ ฅํ•ด ์ฃผ๊ณ , ID์—๋Š” ํ•ด๋‹น Credentials์— ์ด๋ฆ„์„ ๋„ฃ์–ด์ฃผ๋ฉด ๋˜์š”.

๊ทธ๋ฆฌ๊ณ , Description์—๋Š” ์„ค๋ช…์„ ์ž‘์„ฑํ•ด ์ฃผ๋ฉด ๋œ๋‹ต๋‹ˆ๋‹ค.


๊ทธ๋Ÿฐ ๋’ค create ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ ์ค„๊ฒŒ์š”.


pipeline {
    agent any
    environment {
        WEBHOOK_URL = credentials("Total-Back-Office-BE-Discord-Webhook")
    }
    
    stages {
        stage('Start') {
            steps {
                echo "Hello, Juny hehe!! ๐Ÿ˜€"
            }
        }
    }

    post {
        success {
            discordSend description: "Jenkins CI/CD Trigger Alarm",
                footer: "Build ์„ฑ๊ณต ํ•˜์˜€์–ด์š”. ๐Ÿ˜€",
                link: env.BUILD_URL, result: currentBuild.currentResult,
                title: "Jenkins CI/CD Trigger Discord๋ฅผ ํ†ตํ•ด ๋ฐ›๊ธฐ ์‹œํ—˜ ์ค‘ ์ž…๋‹ˆ๋‹ค.",
                webhookURL: env.WEBHOOK_URL
        }

        failure {
            discordSend description: "Jenkins CI/CD Trigger Alarm",
                footer: "Build ์‹คํŒจ ํ•˜์˜€์–ด์š”. ๐Ÿ˜ข",
                link: env.BUILD_URL, result: currentBuild.currentResult,
                title: "Jenkins CI/CD Trigger Discord๋ฅผ ํ†ตํ•ด ๋ฐ›๊ธฐ ์‹œํ—˜ ์ค‘ ์ž…๋‹ˆ๋‹ค.",
                webhookURL: env.WEBHOOK_URL
        }
    }
}


๊ทธ๋ฆฌ๊ณ  ์œ„์™€ ๊ฐ™์ด jenkins File์„ ์ˆ˜์ •ํ•ด ์ฃผ์—ˆ์–ด์š”.


๋ฐ”๋กœ ์ด ๋ถ€๋ถ„์—์„œ Jenkins Credentials์— ์ง€์ •ํ•ด์ค€ ID ๊ฐ’์„ ํ†ตํ•ด ๋‚ด์šฉ์„ ๊ฐ€์ ธ์˜ค๊ฒŒ ํ•ด ์ฃผ์—ˆ์–ด์š”.


๊ทธ๋Ÿฐ ๋’ค webhook URL ๋ถ€๋ถ„์„ ์œ„์™€ ๊ฐ™์ด ์ˆ˜์ •ํ•ด ์ฃผ์—ˆ์–ด์š”.

๋‹ค์‹œ Push ํ•ด ๋ณผ๊ฒŒ์š”.





์—ญ์‹œ ์œ„์™€ ๊ฐ™์ด ์ž˜ ์ง„ํ–‰๋œ ๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.

 

 

๐Ÿง ์ฐธ๊ณ  ์ž๋ฃŒ

 

jenkins job์ข…๋ฃŒ ํ›„ discord ์•Œ๋ฆผ ์„ค์ •

1. ๊ฐœ์š” CI/C ์‹œ์Šคํ…œ์—์„œ๋Š” Task๊ฐ€ ๋๋‚˜๋ฉด ์‚ฌ์šฉ์ž์—๊ฒŒ ์•Œ๋ฆผ์„ ์ฃผ๋Š” ๊ธฐ๋Šฅ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. jenkins์—์„œ๋Š” job์ด ์ข…๋ฃŒ๋˜๋ฉด post stage์—์„œ ์„ฑ๊ณต/์‹คํŒจ์— ๋”ฐ๋ผ ์•Œ๋ฆผ๊ธฐ๋Šฅ์„ ์ „์†กํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ณต์‹๋ฌธ์„œ์—๋„ ์นœ

malwareanalysis.tistory.com

 

 

์  ํ‚จ์Šค ๋งˆ์Šคํ„ฐ

COUPANG

www.coupang.com

"์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์Šต๋‹ˆ๋‹ค."

 

 

์ด์ „ ๊ธ€: [CI/CD] Jenkins์™€ Gitea ์—ฐ๋™
๋‹ค์Œ ๊ธ€: [CI/CD] ์ •์  ์ฝ”๋“œ ๋ถ„์„ ํˆด SonarQube์™€ Jenkins ์—ฐ๋™

 

 

 

 

728x90
๋ฐ˜์‘ํ˜•