[Jenkins + React16] CI/CD 파이프라인 구축
인프라

[Jenkins + React16] CI/CD 파이프라인 구축

작성일: 2026년 02월 26일

목표

React (Vite) 프로젝트를 main 브랜치에 푸시하면 Jenkins가 빌드 후 Alibaba Cloud OSS에 자동 배포


발생한 문제들

1. NoSuchMethodError: No such DSL method 'aliyunOSSUpload'

원인: 플러그인 설치 불량 또는 재시작 미실행

해결:

  • Jenkins 서버에서 플러그인 파일 수동 삭제 후 재설치
  • Jenkins 재시작 필수

  • 2. InvalidCredentialsException: Access key id should not be null or empty

    잘못된 코드:

    environment {
        ALIYUN_CREDS_ID = 'LTAI5tCrPDaDWZsjM7GNbigM' // ❌ 실제 Access Key
    }
    aliyunOSSUpload(credentialsId: env.ALIYUN_CREDS_ID, ...)
    

    원인credentialsId는 실제 Key 값이 아니라 Jenkins Credential에 등록된 항목 ID를 요구함

    해결:

  • Manage Jenkins > Credentials에서 Alibaba Cloud AK/SK 등록
  • ID: aliyun-oss-creds (이 값을 사용)
  • Access Key ID / Secret 입력
  • Jenkinsfile 수정:
  • environment {
        ALIYUN_CREDS_ID = 'aliyun-oss-creds' // ✅ Credential ID
    }
    

    최종 Jenkinsfile

    pipeline {
        agent any
        environment {
            ALIYUN_CREDS_ID = 'aliyun-oss-creds'
            OSS_BUCKET = 'oss://voidx-ai-add-on'
        }
        stages {
            stage('Install') {
                steps { sh 'npm install' }
            }
            stage('Build') {
                steps { sh 'npm run build' }
            }
            stage('Upload to OSS') {
                steps {
                    script {
                        def bucketName = env.OSS_BUCKET.replace('oss://', '')
                        dir('dist') {
                            aliyunOSSUpload(
                                credentialsId: env.ALIYUN_CREDS_ID,
                                bucketName: bucketName,
                                filesPath: '**/*',
                                targetPath: '/'
                            )
                        }
                    }
                }
            }
        }
    
        post {
            always { deleteDir() }
        }
    }
    

    핵심 교훈

    문제원인해결
    NoSuchMethodError플러그인 미설치/재시작 필요플러그인 재설치 + Jenkins 재시작
    InvalidCredentialsExceptionKey 값 직접 전달Credential ID 전달
    보안 위험Jenkinsfile에 Key 하드코딩Credential 관리자 사용