Jenkins SMTP 설정

  • Jenkins 관리 > Configure System > Extended E-mail Notification
    • SMTP server : STMP 도메인 or IP   (Gmail) smtp.gmail.com
    • SMTP Port : SMTP 포트   (Gmail) 465
    • Credential : SMTP 계정 정보
    • Use SSL 체크

 

Jenkins 파이프라인

  • attachmentsPattern : '**/test*.txt' 
    ( {jenkins_home}/workspace/{job_name} 디렉토리 내에서 test*.txt 형식의 파일을 찾아 첨부함 )
pipeline {
    agent any

    stages {
        stage('Approval') {
            steps {
                script {
                    def html = """
                        <html>
                            <body style=\"font-family: '맑은고딕'\">
                                <table style=\"width: 700px; border-collapse : collapse; border: 1px solid gray;\">
                                    <tr style=\"background-color: #253C59; font-weight: bold; font-size: 20px; color: white;\">
                                        <td style=\"padding-top: 30px; padding-bottom: 30px; padding-left: 20px; \">
                                            타이틀
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style=\"padding-left: 20px;\">
                                            <div style=\"font-size: 18px; margin-top: 20px; margin-bottom: 20px;\">
                                                배포 대상은 아래와 같습니다.
                                            </div>
                                            
                                            <table style=\"border-collapse : collapse;\">
                                                <tr>
                                                    <td style=\"padding: 5px 60px; font-weight: bold; font-size: 18px; color: #253C59; border-bottom: 2px solid #253C59;\">항목</th>
                                                    <td style=\"padding: 5px 225px; font-weight: bold; font-size: 18px; color: #253C59; border-bottom: 2px solid #253C59;\">내용</th>
                                                </tr>
                                                <tr>
                                                    <td style=\"padding-top: 10px; padding-bottom: 10px; font-weight: bold; font-size: 18px; background-color: #99B4BF; text-align: center; \">서비스명</td>
                                                    <td style=\"padding-top: 10px; padding-bottom: 10px; font-size: 18px; text-align: center; \">OOO 서비스</td>
                                                </tr>
                                                <tr>
                                                    <td style=\"padding-top: 10px; padding-bottom: 10px; font-weight: bold; font-size: 18px; background-color: #99B4BF; text-align: center; \">서버</td>
                                                    <td style=\"padding-top: 10px; padding-bottom: 10px; font-size: 18px; text-align: center; \">운영 WAS #1</td>
                                                </tr>
                                                <tr>
                                                    <td style=\"padding-top: 10px; padding-bottom: 10px; font-weight: bold; font-size: 18px; background-color: #99B4BF; text-align: center; \">컨테이너</td>
                                                    <td style=\"padding-top: 10px; padding-bottom: 10px; font-size: 18px; text-align: center; \">tomcat01</td>
                                                </tr>
                                            </table>
                                            <div style=\"font-size: 18px; margin-top: 20px;\">
                                                수정사항을 확인하신 후 승인 부탁드립니다.
                                            </div>
                                            <div style=\"font-size: 14px; margin-top: 5px; color: gray; margin-bottom: 40px;\">
                                                ※ 허용된 IP에서만 승인하실 수 있습니다.
                                            </div>
                                            
                                            <table>
                                                <tr>
                                                    <td style=\"width: 320px; padding: 15px 0; background-color: #253C59; text-align: center;\">
                                                        <a href=\"\" style=\"text-decoration: none; font-size: 18px; color: white; font-weight: bold; text-align: center;\">승인하기</a>
                                                    </td>
                                                    <td style=\"width: 320px; padding: 15px 0; background-color: #BF5149; text-align: center;\">
                                                        <a href=\"\" style=\"text-decoration: none; font-size: 18px; color: white; font-weight: bold; text-align: center;\">반려하기</a>
                                                    </td>
                                                </tr>
                                            </table>
                                            <div style=\"margin-bottom: 20px;\">
                                                &nbsp;
                                            </div>
                                        </td>
                                    </tr>
                                    <tr style=\"background-color: #D1D1D1; font-weight: bold; font-size: 16px; color: gray;\">
                                        <td style=\"padding-top: 10px; padding-bottom: 10px; padding-left: 20px; \">
                                            Copyright
                                        </td>
                                    </tr>
                                </table>
                            </body>
                        </html>
                    """
                       
                    emailext attachmentsPattern: '**/test*.txt',
                    body: "${html}",
                    subject: '[Jenkins] OOO 서비스 배포 승인 요청', 
                    to: '수신 메일주소',
                    mimeType: 'text/html'
                }
            }
        }
    }
}

 

메일 결과화면

복사했습니다!