Vendored
+78
-1
@@ -2,7 +2,7 @@ pipeline {
|
|||||||
agent { label 'djb-vm' }
|
agent { label 'djb-vm' }
|
||||||
|
|
||||||
triggers {
|
triggers {
|
||||||
pollSCM('H/10 * * * *')
|
cron('H/10 * * * *')
|
||||||
}
|
}
|
||||||
|
|
||||||
options {
|
options {
|
||||||
@@ -23,6 +23,8 @@ pipeline {
|
|||||||
CATALINA_HOME = '/prod/eapim/apache-tomcat-9.0.116'
|
CATALINA_HOME = '/prod/eapim/apache-tomcat-9.0.116'
|
||||||
CATALINA_PID = '/prod/eapim/adminportal/temp/catalina.pid'
|
CATALINA_PID = '/prod/eapim/adminportal/temp/catalina.pid'
|
||||||
DEPLOY_HTTP_PORT = '39120'
|
DEPLOY_HTTP_PORT = '39120'
|
||||||
|
REVISION_STATE_FILE = '.jenkins-last-deploy-revisions'
|
||||||
|
SHOULD_DEPLOY = 'true'
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
@@ -43,6 +45,7 @@ pipeline {
|
|||||||
for REPO in elink-online-core elink-online-core-jpa elink-online-transformer elink-online-common elink-online-emsclient; do
|
for REPO in elink-online-core elink-online-core-jpa elink-online-transformer elink-online-common elink-online-emsclient; do
|
||||||
TARGET="eapim-online/$REPO"
|
TARGET="eapim-online/$REPO"
|
||||||
if [ ! -d "$TARGET/.git" ]; then
|
if [ ! -d "$TARGET/.git" ]; then
|
||||||
|
rm -rf "$TARGET"
|
||||||
git clone --depth=1 --branch master \
|
git clone --depth=1 --branch master \
|
||||||
"ssh://git@172.30.1.50:2222/djb-eapim/$REPO.git" \
|
"ssh://git@172.30.1.50:2222/djb-eapim/$REPO.git" \
|
||||||
"$TARGET"
|
"$TARGET"
|
||||||
@@ -55,6 +58,7 @@ pipeline {
|
|||||||
|
|
||||||
for REPO in elink-portal-common eapim-admin-djb; do
|
for REPO in elink-portal-common eapim-admin-djb; do
|
||||||
if [ ! -d "$REPO/.git" ]; then
|
if [ ! -d "$REPO/.git" ]; then
|
||||||
|
rm -rf "$REPO"
|
||||||
git clone --depth=1 --branch master \
|
git clone --depth=1 --branch master \
|
||||||
"ssh://git@172.30.1.50:2222/djb-eapim/$REPO.git" \
|
"ssh://git@172.30.1.50:2222/djb-eapim/$REPO.git" \
|
||||||
"$REPO"
|
"$REPO"
|
||||||
@@ -68,7 +72,53 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stage('Detect changes') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
int status = sh(
|
||||||
|
returnStatus: true,
|
||||||
|
script: '''
|
||||||
|
set -eu
|
||||||
|
current_file="$(mktemp)"
|
||||||
|
{
|
||||||
|
printf 'eapim-admin %s\\n' "$(git rev-parse HEAD)"
|
||||||
|
for REPO in eapim-online/elink-online-core eapim-online/elink-online-core-jpa eapim-online/elink-online-transformer eapim-online/elink-online-common eapim-online/elink-online-emsclient elink-portal-common eapim-admin-djb; do
|
||||||
|
printf '%s %s\\n' "$REPO" "$(git -C "$WORKSPACE/../$REPO" rev-parse HEAD)"
|
||||||
|
done
|
||||||
|
} | sort > "$current_file"
|
||||||
|
|
||||||
|
if [ -f "$REVISION_STATE_FILE" ] && cmp -s "$current_file" "$REVISION_STATE_FILE"; then
|
||||||
|
echo "No repository changes detected. Skipping build and deploy."
|
||||||
|
echo "--- current revisions ---"
|
||||||
|
cat "$current_file"
|
||||||
|
rm -f "$current_file"
|
||||||
|
exit 10
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Repository changes detected. 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
|
||||||
@@ -79,6 +129,9 @@ pipeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stage('Build WAR') {
|
stage('Build WAR') {
|
||||||
|
when {
|
||||||
|
expression { env.SHOULD_DEPLOY == 'true' }
|
||||||
|
}
|
||||||
steps {
|
steps {
|
||||||
sh 'gradle clean build -x test --no-daemon'
|
sh 'gradle clean build -x test --no-daemon'
|
||||||
}
|
}
|
||||||
@@ -96,6 +149,9 @@ pipeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stage('Stop Tomcat') {
|
stage('Stop Tomcat') {
|
||||||
|
when {
|
||||||
|
expression { env.SHOULD_DEPLOY == 'true' }
|
||||||
|
}
|
||||||
steps {
|
steps {
|
||||||
sh '''
|
sh '''
|
||||||
set +e
|
set +e
|
||||||
@@ -114,6 +170,9 @@ pipeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stage('Deploy monitoring.war') {
|
stage('Deploy monitoring.war') {
|
||||||
|
when {
|
||||||
|
expression { env.SHOULD_DEPLOY == 'true' }
|
||||||
|
}
|
||||||
steps {
|
steps {
|
||||||
sh '''
|
sh '''
|
||||||
set -eu
|
set -eu
|
||||||
@@ -126,6 +185,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
|
||||||
@@ -177,4 +239,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