본문 바로가기

개발

Jenkins Pipeline Script Sample

728x90

Jenkins 에서 pipeline 으로 build 구성을 할때 아래와 같이 설정 하면  Git pull -> Build -> Run 순서를 가지는 Pipeline 이 구성된다.

 

pipeline {
    agent any
    // 반복 주기 설정 
    triggers {
        cron('0 22 * * *')
    }
// pipeline Step 
    stages {
        stage('Git Pull') { 
            steps {
                echo "Git Pull"
                git branch: 'master', 
                    credentialsId: '[Jenkins credetial 에서 추가]',
                    url: 'https://github.com/[project]'
            }
        }
        stage('Build') { 
            steps {
                echo "Build"
                sh('gradle build')
    
            }
        }
    
        stage('Run') { 
            steps {
                echo "Run"
                sh('gradle run')
    
            }
        }
    
    }
    
    options {
        // build log 를 남기는 기준 설정, 
        // numToKeepStr : 최근 10개를 남기는 옵션
        buildDiscarder(logRotator(numToKeepStr: '10') )
    }
}