목차
우선 간단한 툴 설정부터 진행한다.
git Repo 설정

적절한 Branch로 설정되어 있는지 항상 주의-

Gradle 빌드 진행

Post build Task 설정 (자료)
Log text ⇒ BUILD SUCCESS
Operation ⇒ AND
Script ⇒ nohup java -jar 이후의 경로만 신경써주면 된다.

echo "Start Spring Boot Application!"
CURRENT_PID=$(ps -ef | grep java | grep test1 | awk '{print $2}')
echo "$CURRENT_PID"
if [ -z $CURRENT_PID ]; then
echo ">현재 구동중인 어플리케이션이 없으므로 종료하지 않습니다."
else
echo "> kill -9 $CURRENT_PID"
kill -9 $CURRENT_PID
sleep 10
fi
echo ">어플리케이션 배포 진행!"
nohup java -jar /var/lib/jenkins/workspace/test1/build/libs/swip-0.0.1-SNAPSHOT.jar &
echo "배포까지 성공 !!"
Run script only if all previous steps were successful ⇒ check
성공 (포트가 겹친다면 소리소문 없이 배포된 프로세스가 종료되니 조심하자)

jenkins : hostURL:9090, Spring boot : hostURL:8080

Jenkins (port 9090)

spring boot (port 8080)
문제점
Jenkins 서버와 Spring Boot 서버를 동시에 하나의 EC2에서 실행시키는 것은 무리가 있다. 때문에 pipeline 혹은 docker를 사용하여, 각기 다른 서버에서 동작하도록 구현할 필요가 있다
FreeStyle로 구축한 환경이 있다면, 크게 추가할 요소가 없다.
그저 pipeline script만 잘 작성하면 된다. (자료 1, 자료 2, 자료 3) 도커 (자료 1, 자료 2 NGINX(자료 1, 자료 2, 자료 3, 자료 4
shell 스크립트 문법 (정리 1,
pipeline script 예제
pipeline {
agent any
tools {
gradle "gradle-test"
}
stages{
stage('Git Pull') {
steps {
git credentialsId: 'dori2005',
url: '<https://github.com/SWYP-LUCKY-SEVEN/back-end.git>',
branch: 'develop'
}
}
stage('secret.yml download') {
steps {
withCredentials([file(credentialsId: 'application-secret-setting', variable: 'secretConfigFile')]) {
script {
sh 'sudo cp $secretConfigFile /var/lib/jenkins/workspace/swyp_pipeline/src/main/resources/application-secret.properties'
}
}
}
}
stage('Build') {
steps {
sh "gradle clean build"
}
}
stage('kill process') {
steps {
sh'''
CURRENT_PID=$(ps -ef | grep java | grep swyp_pipeline | awk '$3 != 1 {print $2}')
if [ ! -z "$CURRENT_PID" ]; then
echo "> kill -9 $CURRENT_PID"
sudo kill -9 $CURRENT_PID
sleep 10
fi
'''
}
}
stage('Deploy') {
steps {
sh "sudo nohup java -jar /var/lib/jenkins/workspace/swyp_pipeline/build/libs/swip-0.0.1-SNAPSHOT.jar &"
}
}
}
}