티스토리 뷰

반응형

1. confirm 확인창 추가

input message: 유저에게 보여줄 메시지, ok: '확인창에 보여줄 메시지(optional)'

pipeline {
    agent any

    stages {
        stage('Confirm Deployment') {
            steps {
                input message: '배포 하시겠습니까?', ok: 'Deploy'
            }
        }
        stage('Description') {
            steps {
                script{
                    currentBuild.description = "description"
                }
            }
        }
    }
}

사용자가 ‘Deploy' 버튼을 클릭하면 파이프라인의 다음 스텝으로 진행합니다. ‘Abort’나 ‘x’ 버튼을 클릭하면 뒤에 있는 스텝들이 진행되지 않고 파이프라인은 종료됩니다.

2. prompt 확인창 추가

  • parameter(optional)
    • 빌드시 사용자에게 하나 이산의 매개변수 값을 지정하도록 요청함
    • 매개 변수가 하나만 지정되면 해당값이 입력 단계의 값이 된다.
    • 매개 변수를 여러개 지정한다면 매개 변수 이름으로 키가 지정된 맵이 된다.
    • 매개 변수를 지정하지 않은 경우 아무 값도 반환하지 않는다.
    • 사용 가능 타입 : string, text, booleanParam, choice, password
    • defaultValue: 기본 입력값
    • description: 파라미터 설명

 

pipeline {
    agent any

    stages {
        stage('Confirm Deployment') {
            steps {
                script {
                    def userInput = input(
                        message: '배포 하시겠습니까?:', 
                        parameters: [string(name: 'PASSPHRASE', defaultValue: '', description: '맞다면 YES 입력')]
                    )
                    // 사용자의 입력 정보를 가져옴. 'YES'를 입력하지 않은 경우 error 반환
                    if (userInput != 'YES') {
                        error "Incorrect passphrase. Deployment aborted."
                    }
                }
            }
        }
        stage('Description') {
            steps {
                script{
                    currentBuild.description = "description"
                }
            }
        }
    }
}

이 스크립트는 사용자가 'YES'를 입력하지 않으면 배포를 중단하고 파이프라인을 ABORTED 상태로 설정합니다.

파라미터를 여러개 사용하고 싶은 경우

pipeline {
    agent any

    stages {
        stage('Confirm Deployment') {
            steps {
                script {
                    def userInput = input(
                        message: '배포 하시겠습니까?:', 
                        parameters: [
                            string(name: 'PASSPHRASE', defaultValue: '', description: '맞다면 YES 입력'),
                            booleanParam(name: 'FORCE_DEPLOY', defaultValue: false, description: '강제 배포 여부')
                            // 추가적으로 필요한 파라미터들을 여기에 추가함.
                        ]
                    )
                    // 사용자의 입력 정보를 가져옴. 파라미터가 여러개인 경우 파라미터 이름을 키로 가진 맵 형식으로 저장됨
                    // 'YES'를 입력하지 않은 경우 error 반환
                    if (userInput.PASSPHRASE != 'YES') {
                        error "Incorrect passphrase. Deployment aborted."
                    }
                    // FORCE_DEPLOY 파라미터에 따라 강제 배포 여부를 처리할 수 있습니다.
                    if (userInput.FORCE_DEPLOY) {
                        // 강제 배포 처리 로직 추가
                    }
                }
            }
        }
        stage('Description') {
            steps {
                script {
                    currentBuild.description = "description"
                }
            }
        }
    }
}

참고

반응형
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함