build pipeline 은 어떻게 구축할 수 있을까?

예시 - S3 배포

pipeline {
// 깃 클론을 받는다.
	stages {
        stage('Git Clone') {
            steps {
                script {
                    try {
                        git branch: 'develop', credentialsId: 'github', url: 'https://github.com/저장소주소'
                        env.cloneResult=true
                    } catch (error) {
                        print(error)
                        env.cloneResult=false
                        currentBuild.result = 'FAILURE'
                    }
                }

            }
        }

// 변경사항을 감지한다. 
        stage('Check Changes') {
            steps {
                script {
                    def paths = [
                        // review
                        'apps/myapp/**',
                        'env/myapp/**',

                        // 공통 참조
                        'libs/shared/**',
                        'libs/design-system/**',
                        'public/**',
                        'babel.config.json',
                        'index.d.ts',
                        'nx.json',
                        'package.json',
                        'tsconfig.base.json',
                        'workspace.json',
                        'yarn.lock'
                    ].collect {
                        it.replaceAll(/(\*\*)$/, '*').replace('*', '.*')
                    }

                    println "ChangeSets: ${currentBuild.changeSets}"

                    def changeSetsEmpty = currentBuild.changeSets.isEmpty()
// 변경사항이 하나라도 있는지 확인한다.
                    shouldBuild = changeSetsEmpty || currentBuild.changeSets.flatten().items.any { entry ->
                        entry.affectedFiles.any { file ->
                            def filePathMatches = paths.any { path ->
                                def match = file.path ==~ path
                                if (match) {
                                    println "Match found: File Path ${file.path} matches with Path ${path}"
                                } else {
                                    println "No match: File Path ${file.path} does not match with Path ${path}"
                                }
                                return match
                            }

                            if (filePathMatches) {
                                println "File Path Matches found for file: ${file.path}"
                            }

                            return filePathMatches
                        }
                    }

                    println "Should Build: ${shouldBuild}"
                }
            }
        }

// 빌드한다 (변경사항이 있으면)
        stage('Build') {
            when {
                expression { return shouldBuild }
            }
            steps {
                sh 'rm -rf dist'
                sh 'yarn'
                sh 'yarn build myapp dev'
                echo "Running ${currentBuild.number} on ${env.JENKINS_URL}"
            }
            post {
                success {
                  echo 'Build Success !'
                }
                failure {
                  echo 'Build Failure !'
            }
        }

        stage('S3 Deploy') {
            when {
                expression { return shouldBuild }
            }
            steps{
                script{
                    try {
                        sh 'aws s3 sync dist/apps/myapp/exported s3://기존위치 --delete'
                    } catch (error) {
                        print(error)
                        currentBuild.result = 'FAILURE'
                    }
                }
            }
            post {
                success {
                    echo "The S3 Deploy stage successfully."
                }
                failure {
                    echo "The S3 Deploy stage failed."
                }
            }
        }
        
        stage('Clean Up') {
            steps {
                sh 'rm -rf dist'
            }
        }

        stage('Finish') {
            when {
                expression { return shouldBuild }
            }
        }
    }
}