사용자 도구

사이트 도구


ci:jenkins:pipeline

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판 양쪽 다음 판
ci:jenkins:pipeline [2018/11/28 15:44]
kwon37xi
ci:jenkins:pipeline [2018/11/28 16:08]
kwon37xi [JUnit 테스트 결과 메일/Slack 발송]
줄 117: 줄 117:
 </scriptApproval> </scriptApproval>
 </code> </code>
 +  * 선언적 파이프라인 구성시에 최상단에(''pipeline' 블록 전에) import와 테스트 메시지용 변수를 미리 선언한다.
  
 +<code groovy>
 +import jenkins.model.*
 +import hudson.tasks.test.AbstractTestResultAction
 +
 +String testResultMessage = '테스트가 올바로 실행되지 못했음' // 이 변수에 테스트 메시지 저장
 +
 +pipeline {
 +    stages {
 +
 +        stage('Test Reports') {
 +            steps {
 +                junit '**/build/test-results/**/*.xml'
 +
 +                script {
 +                    AbstractTestResultAction testResultAction =  currentBuild.rawBuild.getAction(AbstractTestResultAction.class)
 +                    if (testResultAction != null) {
 +                        def totalNumberOfTests = testResultAction.totalCount
 +                        def failedNumberOfTests = testResultAction.failCount
 +                        def failedDiff = testResultAction.failureDiffString
 +                        def skippedNumberOfTests = testResultAction.skipCount
 +                        def passedNumberOfTests = totalNumberOfTests - failedNumberOfTests - skippedNumberOfTests
 +                        testResultMessage = "Passed: ${passedNumberOfTests}; Failed: ${failedNumberOfTests} ${failedDiff}; Skipped: ${skippedNumberOfTests}  out of ${totalNumberOfTests}"
 +                    }
 +                }
 +            }
 +        }
 +    }
 +    post {
 +        failure {
 +            slackSend(channel: '#build-ci', color: '#FF0000', message: """빌드 실패: Job ${env.JOB_NAME} [${env.BUILD_NUMBER}] TargetBranch: ${params.GIT_BRANCH} (${env.BUILD_URL})
 + - 테스트 실패 : ${testResultMessage}
 +""")
 +        }
 +    }
 +}
 +</code>
 ===== 참조 ===== ===== 참조 =====
   * [[https://reidweb.com/2017/02/01/what-ive-learnt-about-jenkins-pipelines/|What I've learnt about Jenkins Pipelines]]   * [[https://reidweb.com/2017/02/01/what-ive-learnt-about-jenkins-pipelines/|What I've learnt about Jenkins Pipelines]]
  
ci/jenkins/pipeline.txt · 마지막으로 수정됨: 2022/05/30 23:10 저자 kwon37xi