-
[Jenkins] 조건부 실행CICD 2023. 1. 28. 22:06
조건부 실행
특정 조건이 참일 때 단일 또는 여러 빌드 단계를 실행하도록 설정할 수 있습니다.
스크립팅 파이프라인
스크립팅 파이프라인의 경우 매개변수 , if문 , 피연산자 조합해서 조건부 실행을 구현할 수 있습니다.
node ('worker_node1') { def responses = null stage('selection') { responses = input message: 'Enter branch and select build type', parameters:[string(defaultValue: '', description: '', name: 'BRANCH_NAME'),choice(choices: 'DEBUG\nRELEASE\nTEST', description: '', name: 'BUILD_TYPE')] } stage('process') { if ((responses.BRANCH_NAME == 'master') && (responses.BUILD_TYPE == 'RELEASE')) { echo "Kicking off production build\n" } } }
선언적 파이프라인
선언적 파이프라인은 매개변수 , when , allof , expression문을 조합해서 조건부 실행을 구현할 수 있습니다.
pipeline { agent any parameters { string(defaultValue: '', description: '', name : 'BRANCH_NAME') choice ( choices: 'DEBUG\nRELEASE\nTEST', description: '', name : 'BUILD_TYPE') } stages { stage('process') { when { allOf { expression {params.BRANCH_NAME == "master"} expression {params.BUILD_TYPE == 'RELEASE'} } } steps { echo "Kicking off production build\n" } } } }
'CICD' 카테고리의 다른 글