[CI/CD] Jenkins와 Mattermost 연동

RUNGOAT·2023년 4월 29일
0

CI/CD

목록 보기
6/11
post-thumbnail

1️⃣   MatterMost 설정

1.1 통합

1.2 전체 Incoming Webhook

1.3 Incoming Webhook 추가하기

1.4 추가

  • 제목 : 임의의 제목
  • 설명 : 설명
  • 채널 : 메세지를 받을 채널 선택

1.5 확인

  • 이 URL이 Endpoint URL이며 아래 2.2 설정에 입력한다.

2️⃣   Jenkins 설정

2.1 Mattermost Notification Plugin 설치

Jenkins 관리 - 플러그인 관리 - Available plugins에서
Mattermost Notification Plugin을 설치

2.2 Global Mattermost Notifier Settings 설정

Jenkins 관리 - 시스템 설정에서
Global Mattermost Notifier Settings 설정

  • Endpoint: 위에서 언급한 URL 입력
  • Channel: Incoming Webhook을 추가할 때 설정했던 채널 이름
  • Build Server URL: Jenkins 주소 (자동으로 입력되어 있을 것이다.)

설정 후 사진 아래의 Test Connection을 눌러보면 사진 하단 왼쪽 부근에 Success가 나타날 것이다!

2.3 Pipeline 설정

Item을 Pipeline으로 설정했기에 해당 방법의 사용법을 작성하겠습니다.

pipeline {
    agent any
    
    stages {
        
        stage('git_clone') {
            # ...
        }
        
        # ...
    }
    post {
        success {
        	script {
                def Author_ID = sh(script: "git show -s --pretty=%an", returnStdout: true).trim()
                def Author_Name = sh(script: "git show -s --pretty=%ae", returnStdout: true).trim()
                mattermostSend (color: 'good', 
                message: "빌드 성공: ${env.JOB_NAME} #${env.BUILD_NUMBER} by ${Author_ID}(${Author_Name})\n(<${env.BUILD_URL}|Details>)", 
                endpoint: '{endpoint입력}', 
                channel: '{channel입력}'
                )
            }
        }
        failure {
        	script {
                def Author_ID = sh(script: "git show -s --pretty=%an", returnStdout: true).trim()
                def Author_Name = sh(script: "git show -s --pretty=%ae", returnStdout: true).trim()
                mattermostSend (color: 'danger', 
                message: "빌드 실패: ${env.JOB_NAME} #${env.BUILD_NUMBER} by ${Author_ID}(${Author_Name})\n(<${env.BUILD_URL}|Details>)", 
                endpoint: '{endpoint입력}', 
                channel: '{channel입력}'
                )
            }
        }
    }
}

3️⃣   결과

성공

실패


📌 참고

profile
📞피드백 너무나 환영

0개의 댓글