Jenkins

[Jenkins] Pipeline - 조건문 if

비번변경 2023. 11. 9. 15:21

개요

2023.11.08 - [Jenkins] Pipeline - for 반복문 에서는 Jenkins 파이프라인에서 반복문을 사용하는 방법을 확인했는데, 이번 글에서는 조건문 if를 사용해보려고 한다.

 

 

if 문

소괄호 내에 조건절을 기재하고, 중괄호를 블록을 묶는다.

if(condition) { 
   statement #1 
   statement #2 
   ... 
} else{ 
   statement #3 
   statement #4  
}

 

 

사용 예시

아래 예시는 간단히 boolean형 데이터로 초기화한 변수 값에 따라 분기 처리한 파이프라인이다. true 또는 false를 사용할 때는 전체 소문자로 기재한다.

pipeline {
    agent any
    stages {
        stage('Example') {
            steps {
                script {
                    boolean flag = true
                    if (flag == true) {
                        println true
                    }
                    else {
                        println false
                    }
                }
            }
        }
    }
}

 

 

참고 문서

https://www.tutorialspoint.com/groovy/groovy_if_else_statement.htm

https://naiveskill.com/jenkins-pipeline-if-statement/

 

728x90