[Jenkins] Jenkins를 활용한 CI/CD 파이프라인 구축 (1)

Jenkins, EC2, AWS, Docker, CI/CD

Featured image

[Jenkins] Jenkins를 활용한 CI/CD 파이프라인 구축 (1)

1. CI/CD란?


CI/CD 파이프라인 모식도




2. Jenkins란?





3. Pipeline Syntax



 post {
     // If it was able to run the tests, record the test results and archive the jar file.
     success {
         echo 'success'
     }
}


post {
    success {
        mail  to: 'dk02315@gmail.com',
              subject: "Deploy Success",
              body: "Successfully deployed!"
          
    }
}


stages {
    stage('Prepare') {
        steps {
            git url: 'https://github.com/yeonghyeonKO/Archaeology.git',
                branch: 'master',
                credentialsId: 'jenkinsgit'
            sh 'ls'
            dir ('./docs') {
                sh ``
                aws s3 sync ./ s3://yeonghyeontest
                `` // ` 두 개가 아니라 세 개 붙여야 함.
            }
        }
        
        post {
             success {
                 echo 'success'
             }
        }
    }
    
    stage('Build') {
        steps {
            echo 'Building...'
        }
    }
}         

위 코드는 Stages 및 내부의 Steps Section이 어떻게 돌아가는지 보여준다.


 environment {
     AWS_ACCESS_KEY_ID = credentials('awsAccessKeyId')
     AWS_SECRET_ACCESS_KEY = credentials('awsSecretAccessKey')
     AWS_DEFAULT_REGION = 'ap-northeast-2'
     HOME = '.' // Avoid npm root owned
 }
 stage('Only for production') {
     when {
         branch 'production'
         environment name: 'APP_ENV', value: 'prod'
         anyOf {
             environment name: 'DEPLOY_TO', value: 'production'
             environment name: 'DEPLOY_TO', value: 'staging'
         }
     }
 }





참고자료 : T-Academy Jenkins를 활용한 CI/CD