Jenkins 설치


# Java 설치
sudo apt-get install openjdk-11-jdk

# 1. Jenkins 저장소 key 다운로드
# 2. sources.list 추가
# 3. key 등록
# 4. jenkins 설치
wget -q -O - <https://pkg.jenkins.io/debian/jenkins-ci.org.key> | sudo apt-key add -
echo deb <http://pkg.jenkins.io/debian-stable> binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys FCEF32E745F2C3D5
sudo apt-get update
sudo apt-get install jenkins

# Jenkins 서버 포트 번호 변경
sudo vi /etc/default/jenkins
# Jenkins 서비스 재기동
sudo service jenkins restart
# Jenkins 서비스 상태 확인
sudo systemctl status jenkins
# Jenkins 초기 비밀번호 확인
sudo cat /var/lib/jenkins/secrets/initialAdminPassword

# jenkins포트 설정 후 변경하는 법
sudo chmod 777 /usr/lib/systemd/system/jenkins.service
sudo vi /usr/lib/systemd/system/jenkins.service
sudo chmod 444 /usr/lib/systemd/system/jenkins.service
sudo systemctl daemon-reload
sudo service jenkins restart

jenkins id & pw

ssafyland

OBh00UOs4dq8

Jenkins & gitlab 연동


deploy token : gitlab+deploy-token-3725

token pw : XaRCBzDRnLBH2D2qcXo1

jenkins secret token : 4fa094f6225d8c9899db272b2ad310db

gitlab deploy token 생성

project - Settings - Repository - Deploy tokens

jenkins pipeline 생성 및 script

pipeline {
    agent any
    
    tools {
        nodejs 'node:16.13.2'
    }
    
    environment {
		GIT_URL = "<https://gitlab+deploy-token-3725:[email protected]/s06-final/S06P31D102.git>"
    }
    
    stages {
        stage('pull') {
            steps {
                git branch: 'develop', url: "${GIT_URL}"
                sh 'git lfs pull'
            }
        }
        
        stage('build') {
            steps {
                dir('frontend') {
                    sh 'npm install && npm run build'    
                }
                
                dir('backend') {
                    sh './gradlew clean build'
                }
            }
        }
        
        stage('deploy') {
            steps {
                sh 'docker-compose up -d --build --force-recreate'
            }
        }
    }
}