From a8323e78f5dd7bbc57676f522b10b767e9b51531 Mon Sep 17 00:00:00 2001 From: rinjae Date: Thu, 18 Jun 2026 12:11:00 +0900 Subject: [PATCH] =?UTF-8?q?Jenkinsfile.deploy=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile.deploy | 105 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 96 insertions(+), 9 deletions(-) diff --git a/Jenkinsfile.deploy b/Jenkinsfile.deploy index 0dd45e7..2116151 100644 --- a/Jenkinsfile.deploy +++ b/Jenkinsfile.deploy @@ -1,8 +1,8 @@ pipeline { agent { label 'djb-vm' } - parameters { - string(name: 'BRANCH', defaultValue: 'master', description: 'Branch to deploy') + triggers { + cron('H/10 * * * *') } options { @@ -23,16 +23,14 @@ pipeline { CATALINA_HOME = '/prod/eapim/apache-tomcat-9.0.116' CATALINA_PID = '/prod/eapim/devportal/temp/catalina.pid' DEPLOY_HTTP_PORT = '39130' + REVISION_STATE_FILE = '.jenkins-last-deploy-revisions' + SHOULD_DEPLOY = 'true' } stages { stage('Checkout') { steps { - checkout([ - $class: 'GitSCM', - branches: [[name: "*/${params.BRANCH}"]], - userRemoteConfigs: [[url: 'ssh://git@172.30.1.50:2222/djb-eapim/eapim-portal.git']] - ]) + checkout scm } } @@ -43,6 +41,7 @@ pipeline { cd "$WORKSPACE/.." if [ ! -d elink-portal-common/.git ]; then + rm -rf elink-portal-common git clone --depth=1 --branch master \ ssh://git@172.30.1.50:2222/djb-eapim/elink-portal-common.git \ elink-portal-common @@ -54,6 +53,7 @@ pipeline { mkdir -p eapim-online if [ ! -d eapim-online/elink-online-core-jpa/.git ]; then + rm -rf eapim-online/elink-online-core-jpa git clone --depth=1 --branch master \ ssh://git@172.30.1.50:2222/djb-eapim/elink-online-core-jpa.git \ 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') { + when { + expression { env.SHOULD_DEPLOY == 'true' } + } steps { sh ''' set -eu @@ -76,9 +121,27 @@ pipeline { } } - stage('Build WAR') { + stage('Test') { + when { + expression { env.SHOULD_DEPLOY == 'true' } + } 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 { success { @@ -94,6 +157,9 @@ pipeline { } stage('Stop Tomcat') { + when { + expression { env.SHOULD_DEPLOY == 'true' } + } steps { sh ''' set +e @@ -112,6 +178,9 @@ pipeline { } stage('Deploy ROOT.war') { + when { + expression { env.SHOULD_DEPLOY == 'true' } + } steps { sh ''' set -eu @@ -124,6 +193,9 @@ pipeline { } stage('Start Tomcat and readiness') { + when { + expression { env.SHOULD_DEPLOY == 'true' } + } steps { sh ''' 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 + ''' + } + } + } + } }