Jenkinsfile.deploy 업데이트
This commit is contained in:
+96
-9
@@ -1,8 +1,8 @@
|
|||||||
pipeline {
|
pipeline {
|
||||||
agent { label 'djb-vm' }
|
agent { label 'djb-vm' }
|
||||||
|
|
||||||
parameters {
|
triggers {
|
||||||
string(name: 'BRANCH', defaultValue: 'master', description: 'Branch to deploy')
|
cron('H/10 * * * *')
|
||||||
}
|
}
|
||||||
|
|
||||||
options {
|
options {
|
||||||
@@ -23,16 +23,14 @@ pipeline {
|
|||||||
CATALINA_HOME = '/prod/eapim/apache-tomcat-9.0.116'
|
CATALINA_HOME = '/prod/eapim/apache-tomcat-9.0.116'
|
||||||
CATALINA_PID = '/prod/eapim/devportal/temp/catalina.pid'
|
CATALINA_PID = '/prod/eapim/devportal/temp/catalina.pid'
|
||||||
DEPLOY_HTTP_PORT = '39130'
|
DEPLOY_HTTP_PORT = '39130'
|
||||||
|
REVISION_STATE_FILE = '.jenkins-last-deploy-revisions'
|
||||||
|
SHOULD_DEPLOY = 'true'
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
stage('Checkout') {
|
stage('Checkout') {
|
||||||
steps {
|
steps {
|
||||||
checkout([
|
checkout scm
|
||||||
$class: 'GitSCM',
|
|
||||||
branches: [[name: "*/${params.BRANCH}"]],
|
|
||||||
userRemoteConfigs: [[url: 'ssh://git@172.30.1.50:2222/djb-eapim/eapim-portal.git']]
|
|
||||||
])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,6 +41,7 @@ pipeline {
|
|||||||
cd "$WORKSPACE/.."
|
cd "$WORKSPACE/.."
|
||||||
|
|
||||||
if [ ! -d elink-portal-common/.git ]; then
|
if [ ! -d elink-portal-common/.git ]; then
|
||||||
|
rm -rf elink-portal-common
|
||||||
git clone --depth=1 --branch master \
|
git clone --depth=1 --branch master \
|
||||||
ssh://git@172.30.1.50:2222/djb-eapim/elink-portal-common.git \
|
ssh://git@172.30.1.50:2222/djb-eapim/elink-portal-common.git \
|
||||||
elink-portal-common
|
elink-portal-common
|
||||||
@@ -54,6 +53,7 @@ pipeline {
|
|||||||
|
|
||||||
mkdir -p eapim-online
|
mkdir -p eapim-online
|
||||||
if [ ! -d eapim-online/elink-online-core-jpa/.git ]; then
|
if [ ! -d eapim-online/elink-online-core-jpa/.git ]; then
|
||||||
|
rm -rf eapim-online/elink-online-core-jpa
|
||||||
git clone --depth=1 --branch master \
|
git clone --depth=1 --branch master \
|
||||||
ssh://git@172.30.1.50:2222/djb-eapim/elink-online-core-jpa.git \
|
ssh://git@172.30.1.50:2222/djb-eapim/elink-online-core-jpa.git \
|
||||||
eapim-online/elink-online-core-jpa
|
eapim-online/elink-online-core-jpa
|
||||||
@@ -66,7 +66,52 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stage('Detect changes') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
int status = sh(
|
||||||
|
returnStatus: true,
|
||||||
|
script: '''
|
||||||
|
set -eu
|
||||||
|
current_file="$(mktemp)"
|
||||||
|
{
|
||||||
|
printf 'eapim-portal %s\\n' "$(git rev-parse HEAD)"
|
||||||
|
printf 'elink-portal-common %s\\n' "$(git -C "$WORKSPACE/../elink-portal-common" rev-parse HEAD)"
|
||||||
|
printf 'eapim-online/elink-online-core-jpa %s\\n' "$(git -C "$WORKSPACE/../eapim-online/elink-online-core-jpa" rev-parse HEAD)"
|
||||||
|
} | sort > "$current_file"
|
||||||
|
|
||||||
|
if [ -f "$REVISION_STATE_FILE" ] && cmp -s "$current_file" "$REVISION_STATE_FILE"; then
|
||||||
|
echo "No repository changes detected. Skipping test, build and deploy."
|
||||||
|
echo "--- current revisions ---"
|
||||||
|
cat "$current_file"
|
||||||
|
rm -f "$current_file"
|
||||||
|
exit 10
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Repository changes detected. Test, build and deploy will run."
|
||||||
|
echo "--- previous revisions ---"
|
||||||
|
[ -f "$REVISION_STATE_FILE" ] && cat "$REVISION_STATE_FILE" || echo "(none)"
|
||||||
|
echo "--- current revisions ---"
|
||||||
|
cat "$current_file"
|
||||||
|
mv "$current_file" .jenkins-current-deploy-revisions
|
||||||
|
'''
|
||||||
|
)
|
||||||
|
if (status == 10) {
|
||||||
|
env.SHOULD_DEPLOY = 'false'
|
||||||
|
currentBuild.description = 'No repo changes'
|
||||||
|
} else if (status != 0) {
|
||||||
|
error "Revision change detection failed with status ${status}"
|
||||||
|
} else {
|
||||||
|
env.SHOULD_DEPLOY = 'true'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stage('Verify toolchain') {
|
stage('Verify toolchain') {
|
||||||
|
when {
|
||||||
|
expression { env.SHOULD_DEPLOY == 'true' }
|
||||||
|
}
|
||||||
steps {
|
steps {
|
||||||
sh '''
|
sh '''
|
||||||
set -eu
|
set -eu
|
||||||
@@ -76,9 +121,27 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Build WAR') {
|
stage('Test') {
|
||||||
|
when {
|
||||||
|
expression { env.SHOULD_DEPLOY == 'true' }
|
||||||
|
}
|
||||||
steps {
|
steps {
|
||||||
sh 'gradle clean build -x test --no-daemon'
|
sh 'gradle clean test --no-daemon'
|
||||||
|
}
|
||||||
|
post {
|
||||||
|
always {
|
||||||
|
junit allowEmptyResults: true, testResults: 'build/test-results/test/*.xml'
|
||||||
|
archiveArtifacts allowEmptyArchive: true, artifacts: 'build/reports/tests/test/**,build/test-results/test/**'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Build WAR') {
|
||||||
|
when {
|
||||||
|
expression { env.SHOULD_DEPLOY == 'true' }
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
sh 'gradle build -x test --no-daemon'
|
||||||
}
|
}
|
||||||
post {
|
post {
|
||||||
success {
|
success {
|
||||||
@@ -94,6 +157,9 @@ pipeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stage('Stop Tomcat') {
|
stage('Stop Tomcat') {
|
||||||
|
when {
|
||||||
|
expression { env.SHOULD_DEPLOY == 'true' }
|
||||||
|
}
|
||||||
steps {
|
steps {
|
||||||
sh '''
|
sh '''
|
||||||
set +e
|
set +e
|
||||||
@@ -112,6 +178,9 @@ pipeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stage('Deploy ROOT.war') {
|
stage('Deploy ROOT.war') {
|
||||||
|
when {
|
||||||
|
expression { env.SHOULD_DEPLOY == 'true' }
|
||||||
|
}
|
||||||
steps {
|
steps {
|
||||||
sh '''
|
sh '''
|
||||||
set -eu
|
set -eu
|
||||||
@@ -124,6 +193,9 @@ pipeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stage('Start Tomcat and readiness') {
|
stage('Start Tomcat and readiness') {
|
||||||
|
when {
|
||||||
|
expression { env.SHOULD_DEPLOY == 'true' }
|
||||||
|
}
|
||||||
steps {
|
steps {
|
||||||
sh '''
|
sh '''
|
||||||
set -eu
|
set -eu
|
||||||
@@ -179,4 +251,19 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
success {
|
||||||
|
script {
|
||||||
|
if (env.SHOULD_DEPLOY == 'true') {
|
||||||
|
sh '''
|
||||||
|
set -eu
|
||||||
|
if [ -f .jenkins-current-deploy-revisions ]; then
|
||||||
|
mv .jenkins-current-deploy-revisions "$REVISION_STATE_FILE"
|
||||||
|
fi
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user