[DevOps] Jenkins Build ๋‚ด์šฉ Slack ์œผ๋กœ ์•Œ๋ฆผ ๋ฐ›๊ธฐ

2022. 8. 31. 20:28ใ†System ์ž‘์—…์‹ค/DevOps

728x90
๋ฐ˜์‘ํ˜•




๐Ÿ—‚ ๋ชฉ์ฐจ

โ— [Synology NAS] ๋‚˜๋งŒ์˜ GitHub ๋งŒ๋“ค๊ธฐ - Git Server์™€  Gitea ์„ค์น˜
โ— [Synology NAS] ๋‚˜๋งŒ์˜ Jenkins ๋งŒ๋“ค๊ธฐ 
โ—[DevOps] GitHub์™€ Jenkins ์—ฐ๊ฒฐ  
โ— [DevOps] Jenkins Build ๋‚ด์šฉ Slack ์œผ๋กœ ์•Œ๋ฆผ ๋ฐ›๊ธฐ
 
โ— [DevOps] Jenkins Github Multi Branch Pipe Line ๊ตฌ์„ฑ

 




๐Ÿš€ Jenkins์™€ Slack ์—ฐ๊ฒฐ ํ•˜๊ธฐ

    ๐Ÿ”ฝ  Slack ์„ค์ •

        ๐Ÿ“ฆ Application ๋‚ด๋ ค๋ฐ›๊ธฐ

์ตœ์ดˆ Slack์—์„œ ์•ฑ ์ถ”๊ฐ€๋ฅผ ๋ˆŒ๋Ÿฌ์ค๋‹ˆ๋‹ค.



๊ฒ€์ƒ‰์ฐฝ์— jenkins๋ฅผ ์ž…๋ ฅํ•˜์—ฌ Jenkins CI App์„ ์ฐพ๊ณ , ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.



๊ตฌ์„ฑ์„ ๋ˆŒ๋Ÿฌ์ค๋‹ˆ๋‹ค.



Web Page์—์„œ ์œ„์™€ ๊ฐ™์€ ์ฐฝ์ด ๋œจ๋ฉด install์„ ๋ˆŒ๋Ÿฌ ์„ค์น˜ํ•ด ์ค๋‹ˆ๋‹ค.




Slack ์•Œ๋ฆผ์„ ๋ฐ›์„ ์ฑ„๋„(๋ฐฉ)์„ ์„ ํƒํ•œ ๋’ค Jenkins CI ํ†ตํ•ฉ ์•ฑ ์ถ”๊ฐ€๋ฅผ ๋ˆŒ๋Ÿฌ์ค๋‹ˆ๋‹ค.



์œ„์™€ ๊ฐ™์ด ๋ฐฉ๋ฒ•์„ ์•Œ๋ ค์ฃผ๋Š”๋ฐ, ๊ทธ๋Œ€๋กœ ๋”ฐ๋ผํ•˜๋ฉด ๋˜๊ณ , ํŒ€ ํ•˜์œ„ ๋„๋ฉ”์ธ, ํ†ตํ•ฉ ํ† ํฐ ์ž๊ฒฉ์ฆ๋ช… ID๋ฅผ Jenkins์— ์ž…๋ ฅํ•ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์žŠ์–ด๋ฒ„๋ฆฌ์ง€ ์•Š๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.


 

 

 

 

    ๐Ÿ”ฝ  Jenkins ์„ค์ •

        ๐Ÿ“ฆ Jenkins์™€ Slack ์—ฐ๋™


Jenkins์—์„œ Manage Jekins๋ฅผ ๋ˆŒ๋Ÿฌ์ค๋‹ˆ๋‹ค.




ํ”Œ๋Ÿฌ๊ทธ์ธ ๊ด€๋ฆฌ๋ฅผ ๋ˆŒ๋Ÿฌ์ค๋‹ˆ๋‹ค.



728x90


์„ค์น˜ ๊ฐ€๋Šฅ Tab์—์„œ Slack Notification Plugin์„ ์„ค์น˜ํ•ด ์ค๋‹ˆ๋‹ค.



 

 

 

 

        ๐Ÿ“ฆ Slack Notification ์„ค์ •

Main ํ™”๋ฉด์—์„œ Jenkins ๊ด€๋ฆฌ์—์„œ ์‹œ์Šคํ…œ ์„ค์ •(Configure System)์„ ๋ˆŒ๋Ÿฌ์ค๋‹ˆ๋‹ค.


 


Workspace์— Slack์—์„œ Jenkins CI App ์„ค์ • ์‹œ ๋ฐ›์•˜๋˜ ํŒ€ ํ•˜์œ„ ๋„๋ฉ”์ธ์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.

Defulat chanel / member id ์—๋Š” ์•Œ๋ฆผ์„ ๋ฐ›์„ Slack Chanel ์ด๋ฆ„์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.

๊ทธ๋Ÿฐ ๋’ค Credentials์— Add๋ฅผ ๋ˆŒ๋Ÿฌ์ค๋‹ˆ๋‹ค.





๋ฐ˜์‘ํ˜•

 

Slack์—์„œ Jenkins CI App ๊ตฌ์„ฑ ์‹œ ํ†ตํ•ฉ ํ† ํฐ ์ž๊ฒฉ ์ฆ๋ช… ID๊ฐ’์„ Secret๋ž€์— ์ ์–ด์ฃผ๊ณ , ID๋Š” ์›ํ•˜๋Š” ๊ฐ’์„ ์ž…๋ ฅํ•œ ๋’ค Add๋ฅผ ๋ˆŒ๋Ÿฌ์ฃผ์„ธ์š”.



Test Connection์„ ๋ˆŒ๋Ÿฌ Slack์— ์•Œ๋ฆผ์ด ์˜ค๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.





๋ชจ๋‘ ์™„๋ฃŒ ๋˜๋ฉด ์•„๋ž˜ ์ €์žฅ(Save)๋ฅผ ๋ˆŒ๋Ÿฌ ํ•ด๋‹น ์ฐฝ์„ ๋น ์ ธ ๋‚˜๊ฐ‘๋‹ˆ๋‹ค.




์•Œ๋ฆผ์„ ๋ฐ›์„ Project ์ด๋ฆ„์„ ์„ ํƒํ•ด ์ค๋‹ˆ๋‹ค.


๊ตฌ์„ฑ์„ ๋ˆŒ๋Ÿฌ์ค๋‹ˆ๋‹ค.



๋นŒ๋“œ ํ›„ ์กฐ์น˜ ์ถ”๊ฐ€๋ฅผ ๋ˆŒ๋Ÿฌ ์ค๋‹ˆ๋‹ค.


Slack Notifications๋ฅผ ์„ ํƒํ•ด ์ค๋‹ˆ๋‹ค.



์•Œ๋ฆผ ๋ฐ›๊ณ ์ž ํ•˜๋Š” ๋‚ด์šฉ์„ ์„ ํƒํ•ด ์ค๋‹ˆ๋‹ค.


๊ทธ๋Ÿฐ ๋’ค ์ €์žฅ(Save)๋ฅผ ๋ˆŒ๋Ÿฌ์ค๋‹ˆ๋‹ค.


์ข€ ๋” ์ž์„ธํ•œ ๋‚ด์šฉ์„ ๋ฐ›๊ธฐ ์œ„ํ•ด ์„ค์ • Script๋ฅผ ์ž‘์„ฑํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.



์œ„์™€ ๊ฐ™์ด Project root directory์— jenkinsfile-ci๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.


pipeline {
    agent any

    environment {
   	PATH = "/opt/gradle/gradle-6.8/bin:$PATH"
   	SLACK_CHANNEL = '#jenkins' // ์ฑ„๋„
    	TEAM_DOMAIN = 'black-postoffice' // ์›Œํฌ์ŠคํŽ˜์ด์Šค
    	TOKEN_CREDENTIAL_ID = 'junghyungil-Slack'// ์œ„์—์„œ ์ž‘์„ฑํ•œ ํ† ํฐ

    }

    stages {

        stage('Start') {
            steps {
           	// channel, temaDomainm, tokenCredentialId์€ ์  ํ‚จ์Šค-์Šฌ๋ž™ ์—ฐ๋™์‹œ ์‰˜ ์Šคํฌ๋ฆฝํŠธ ๋ฌธ๋ฒ•์—์„œ ์ง€์›ํ•ด์ฃผ๋Š” ์„ค์ • ๊ฐ’๋“ค์ž…๋‹ˆ๋‹ค. ์ด ์„ค์ •๊ฐ’๋“ค์— environment { ... } ์—์„œ ์ž‘์„ฑํ•œ ๊ฐ’๋“ค์„ ์ดˆ๊ธฐํ™” ํ•ด์ค๋‹ˆ๋‹ค
                slackSend (channel: SLACK_CHANNEL, color: '#FFFF00', message: "STARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})", teamDomain: TEAM_DOMAIN, tokenCredentialId: TOKEN_CREDENTIAL_ID )
            }
        }

        stage('Git Checkout') {
            steps {
                checkout scm
                echo 'Git Checkout Success!'
            }
        }

        stage('Build') {
            steps {
                sh 'gradle clean build --exclude-task test'
                echo 'Build Success!'
            }
        }

        stage('Test') {
            steps {
                sh 'gradle test'
                echo 'Test Success!'
            }
        }

    }

  post {
    success {
         slackSend (channel: SLACK_CHANNEL, color: '#00FF00', message: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})", teamDomain: TEAM_DOMAIN, tokenCredentialId: TOKEN_CREDENTIAL_ID )
         }

    failure {
         slackSend (channel: SLACK_CHANNEL, color: '#F01717', message: "FAILURE: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})", teamDomain: TEAM_DOMAIN, tokenCredentialId: TOKEN_CREDENTIAL_ID )
         }
    }
}


์œ„์™€ ๊ฐ™์ด Script๋ฅผ ์ž…๋ ฅํ•ด ์ค๋‹ˆ๋‹ค.



๊ทธ๋Ÿฐ ๋’ค Github์— push๋ฅผ ํ•ด ์ค๋‹ˆ๋‹ค.



์ง€๊ธˆ ๋นŒ๋“œ๋ฅผ ๋ˆŒ๋Ÿฌ ์ค๋‹ˆ๋‹ค.





์ •์ƒ์ ์œผ๋กœ ์•Œ๋ฆผ์ด ์˜ค๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

 

 

 

 

 

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

https://phoby.github.io/slack-jenkins-notification/

 

Jenkins ๋นŒ๋“œ ์‹คํ–‰ ๊ฒฐ๊ณผ๋ฅผ Slack ์•Œ๋ฆผ์œผ๋กœ ๋ฐ›๊ธฐ

๋งŽ์€ ๊ฐœ๋ฐœ์ž ๋ถ„๋“ค์ด ๊ฐœ๋ฐœํ•˜๋Š” ๊ณผ์ •์—์„œ ํ…Œ์ŠคํŠธ, ๋นŒ๋“œ, ๋ฐฐํฌ๋ฅผ ์ž๋™ํ™”ํ•˜๋Š”๋ฐ Jenkins๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.์ €๋Š” ๊ฐœ๋ฐœ์ž๋Š” ์•„๋‹ˆ์ง€๋งŒ, RestAssured, Selenide ๋“ฑ์˜ ๋„๊ตฌ๋กœ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๊ณ  Jenkins๋ฅผ

phoby.github.io


https://junghyungil.tistory.com/169

 

[Infra] ์  ํ‚จ์Šค์™€ ์Šฌ๋ž™ ์—ฐ๋™ํ•˜์—ฌ ์•Œ๋ฆผ๋ฐ›๊ธฐ

์ด์ „ ๊ธ€์€ ์  ํ‚จ์Šค๋ฅผ ์ด์šฉํ•ด CI๋ฅผ ์ž๋™ํ™”ํ•˜๋Š” ๊ฒƒ์— ๊ด€ํ•ด ๊ธ€์„ ์ž‘์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค. ๋จผ์ € ์ฝ๊ณ ์˜ค์‹œ๋ฉด ์•„๋ž˜ ๋‚ด์šฉ๋“ค์„ ์ดํ•ดํ•˜๋Š”๋ฐ ํฐ ์–ด๋ ค์›€์ด ์—†์œผ์‹ค ๊ฒ๋‹ˆ๋‹ค. ์  ํ‚จ์Šค์™€ ์Šฌ๋ž™ ์—ฐ๋™ํ•˜์—ฌ ์•Œ๋ฆผ๋ฐ›๊ธฐ ์Šฌ๋ž™ ํ™ˆ

junghyungil.tistory.com

https://dnight.tistory.com/entry/Jenkins-Slack-%EC%95%8C%EB%A6%BC-%EC%97%B0%EB%8F%99

 

Jenkins + Slack ์•Œ๋ฆผ ์—ฐ๋™

Jenkins ์—์„œ ๋นŒ๋“œํ›„ Slack์—์„œ ์•Œ๋ฆผ์„ ๋ฐ›์„์ˆ˜ ์žˆ๋„๋ก ์—ฐ๋™ํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. 1. Slack์—์„œ Jenkins์—์„œ ์•Œ๋ฆผ์„ ๋ฐ›์„ ์ฑ„๋„์„ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด ์ค๋‹ˆ๋‹ค. 2.์ฑ„๋„์„ ๋งŒ๋“ ํ›„ Slack ์ขŒ์ธก ํƒญ์˜ App ์˜ + ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ฉ

dnight.tistory.com

 

 

 

 

728x90
๋ฐ˜์‘ํ˜•