Jenkins 통합

공식 Docker 컨테이너를 사용하여 Alpacon을 Jenkins 파이프라인에 통합합니다.

사전 요구사항

  • Docker Pipeline 플러그인이 설치된 Jenkins
  • Alpacon 워크스페이스 및 API 토큰

빠른 시작

1. Credentials 추가

Manage Jenkins → Credentials에서 다음을 추가하세요:

  • ALPACON_WORKSPACE_URL: https://your-workspace.us1.alpacon.io (Secret text)
  • ALPACON_API_TOKEN: API 토큰 (Secret text)

2. 파이프라인 생성

pipeline {
    agent {
        docker {
            image 'alpacax/alpacon-cli:latest'
            args '--entrypoint=""'
        }
    }
 
    environment {
        ALPACON_WORKSPACE_URL = credentials('ALPACON_WORKSPACE_URL')
        ALPACON_API_TOKEN = credentials('ALPACON_API_TOKEN')
    }
 
    stages {
        stage('Deploy') {
            steps {
                sh 'alpacon login $ALPACON_WORKSPACE_URL -t $ALPACON_API_TOKEN'
                sh 'alpacon websh prod-server "cd /app && git pull && pm2 restart app"'
            }
        }
    }
}

중요: 컨테이너의 기본 entrypoint를 override하기 위해 args '--entrypoint=""'가 필요합니다.

사용 예시

원격 명령 실행

pipeline {
    agent {
        docker {
            image 'alpacax/alpacon-cli:latest'
            args '--entrypoint=""'
        }
    }
 
    environment {
        ALPACON_WORKSPACE_URL = credentials('ALPACON_WORKSPACE_URL')
        ALPACON_API_TOKEN = credentials('ALPACON_API_TOKEN')
        TARGET_SERVER = 'prod-server'
    }
 
    stages {
        stage('Deploy') {
            steps {
                sh 'alpacon login $ALPACON_WORKSPACE_URL -t $ALPACON_API_TOKEN'
                sh 'alpacon websh $TARGET_SERVER "echo Hello from Jenkins"'
                sh 'alpacon websh $TARGET_SERVER "pwd"'
                sh 'alpacon websh $TARGET_SERVER "whoami"'
            }
        }
    }
}

Root 권한으로 명령 실행

pipeline {
    agent {
        docker {
            image 'alpacax/alpacon-cli:latest'
            args '--entrypoint=""'
        }
    }
 
    environment {
        ALPACON_WORKSPACE_URL = credentials('ALPACON_WORKSPACE_URL')
        ALPACON_API_TOKEN = credentials('ALPACON_API_TOKEN')
    }
 
    stages {
        stage('Deploy') {
            steps {
                sh 'alpacon login $ALPACON_WORKSPACE_URL -t $ALPACON_API_TOKEN'
                sh 'alpacon websh -r prod-server "whoami"'
                sh 'alpacon websh -r prod-server "docker ps"'
            }
        }
    }
}

문제 해결

Entrypoint 오류

증상: Container doesn’t run the expected command

해결 방법: docker agent 설정에 args '--entrypoint=""'를 반드시 포함해야 합니다.

다음 단계