-
[Jenkins] 사후 처리 - try-catch-finally , catchError , postCICD 2023. 1. 29. 15:22
사후처리( Post-Processing )
파이프라인 진행중에 작업이 완료되고 작업의 성공 여부와 상관없이 작업 종료 후 항상 또는 조건에 따라 실행되는 작업을 추가합니다.
스크립팅 파이프라인
#1 try - catch - finally
try구문에서 실행되는 작업이 실패할 경우 catch구문이 실행되고 finally의 작업은 성공 실패와 상관없이 try가 완료되면 실행됩니다.
def err = null try { // pipeline code node ('node-name') { stage ('first stage') { ... } // end of last stage } } catch (err) { currentBuild.result = "FAILURE" } finally { (currentBuild.result != "ABORTED"){ // Send email notifications for builds that failed // or are unstable } }
#2 catchError
catchError구문의 내용을 실행시키고 에러가 발생할 경우 로그에 에러 내용을 출력하고 currentBuild.result에 FAILURE를 할당합니다.
node ('node-name') { catchError { stage ('first stage') { ... } // end of last stage } // step to send email notifications }
선언적 파이프라인
post
post구문은 단계의 끝과 파이프라인의 끝 모두에서 사용될 수 있습니다. 조건에 대한 구문을 통해서 조건이 성립되는 경우 특정 작업을 실행할 수 도있습니다.
조건 종류
- always - 항상 실행
- changed - 현재 빌드의 상태가 이전 빌드의 상태와 다른 경우 실행
- succcess - 현재 빌드가 성공한 경우 실행
- failure - 현재 빌드가 실패한 경우 실행
- unstable - 현재 빌드 상태가 불안정한 경우 실행
} } // end stages post { always { echo "Build stage complete" } failure { echo "Build failed" mail body: 'build failed', subject: 'Build failed!', to: 'devops@company.com' } success { echo "Build succeeded" mail body: 'build succeeded', subject: 'Build Succeeded', to: 'devops@company.com' } } } // end pipeline
'CICD' 카테고리의 다른 글
[Jenkins] 역할 기반 액세스 - Role-based Authorization Strategy Plugin (0) 2023.01.29 [Jenkins] 조건부 실행 (0) 2023.01.28 [Jenkins] stash , unstash - 나중에 빌드에서 사용할 일부 파일을 보관, preserveStashes , failFast (0) 2023.01.28 [Jenkins] disableConcurrentBuilds 구문 - multi branch 파이프라인의 동시성 제한 (0) 2023.01.28 [Jenkins] Milestone Step Plugin - 여러 빌드가 동일한 Step으로 진입하는 것을 제어 (0) 2023.01.27