Update Jenkinsfile
This commit is contained in:
parent
82a7d77e39
commit
f7dcecba8b
73
Jenkinsfile
vendored
73
Jenkinsfile
vendored
@ -1,21 +1,31 @@
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
environment {
|
||||
SSH_CREDENTIALS = 'exceed-sleep'
|
||||
REMOTE_SERVER = 'ubuntu@160.187.167.106'
|
||||
REMOTE_WORKSPACE = '/var/www/html'
|
||||
GIT_CREDENTIALS = 'git-cred'
|
||||
TEST_REPO = 'https://git.tech4biz.wiki/Tech4biz/Spurrin_Frontend_Test.git'
|
||||
TEST_DIR = 'Spurrin_Frontend_Test'
|
||||
BACKEND_TEST_DIR = 'Spurrin_Backend_Test'
|
||||
BACKEND_TEST_REPO = 'https://git.tech4biz.wiki/Tech4biz/Spurrin_Backend_Test.git'
|
||||
BACKEND_TEST_ENV = '/home/ubuntu/test'
|
||||
}
|
||||
|
||||
stages {
|
||||
// ... [Previous stages remain unchanged] ...
|
||||
stage('Add Host Key') {
|
||||
steps {
|
||||
script {
|
||||
sshagent(credentials: [SSH_CREDENTIALS]) {
|
||||
sh """
|
||||
mkdir -p ~/.ssh
|
||||
ssh-keyscan -H ${REMOTE_SERVER.split('@')[1]} >> ~/.ssh/known_hosts
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Run Pytest Validation') {
|
||||
stage('Clone & Build Frontend') {
|
||||
steps {
|
||||
script {
|
||||
withCredentials([usernamePassword(credentialsId: GIT_CREDENTIALS, usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD')]) {
|
||||
@ -24,17 +34,12 @@ pipeline {
|
||||
ssh ${REMOTE_SERVER} '
|
||||
set -e
|
||||
cd ${REMOTE_WORKSPACE}
|
||||
rm -rf ${TEST_DIR}
|
||||
git clone https://${GIT_USERNAME}:${GIT_PASSWORD}@git.tech4biz.wiki/Tech4biz/${TEST_DIR}.git
|
||||
cd ${TEST_DIR}
|
||||
chmod +x run_pipeline.sh
|
||||
/home/ubuntu/venv/bin/bash run_pipeline.sh > pytest_output.log 2>&1 || (
|
||||
echo "Tests failed. Rolling back..." && \
|
||||
cd ${REMOTE_WORKSPACE} && \
|
||||
rm -rf spurrin-dev-ui && \
|
||||
mv spurrin-dev-ui-prev spurrin-dev-ui && \
|
||||
exit 1
|
||||
)
|
||||
if [ -d spurrin-dev-ui ]; then mv spurrin-dev-ui spurrin-dev-ui-prev; fi
|
||||
git clone https://${GIT_USERNAME}:${GIT_PASSWORD}@git.tech4biz.wiki/Tech4Biz-Services/spurrin-dev-ui.git
|
||||
cd spurrin-dev-ui
|
||||
export PATH=/home/ubuntu/.nvm/versions/node/v22.14.0/bin:\$PATH
|
||||
npm install --legacy-peer-deps --force
|
||||
npm run build
|
||||
'
|
||||
"""
|
||||
}
|
||||
@ -57,9 +62,8 @@ pipeline {
|
||||
chmod +x run_tests.sh
|
||||
./run_tests.sh > backend_pytest_output.log 2>&1 || (
|
||||
echo "Backend tests failed. Rolling back..." && \
|
||||
cd ${REMOTE_WORKSPACE} && \
|
||||
rm -rf spurrin-dev-ui && \
|
||||
mv spurrin-dev-ui-prev spurrin-dev-ui && \
|
||||
cd ${REMOTE_WORKSPACE}/spurrin-dev-ui && \
|
||||
git reset --hard HEAD~1 && \
|
||||
exit 1
|
||||
)
|
||||
'
|
||||
@ -78,7 +82,6 @@ pipeline {
|
||||
script {
|
||||
sshagent(credentials: [SSH_CREDENTIALS]) {
|
||||
sh """
|
||||
scp ${REMOTE_SERVER}:${REMOTE_WORKSPACE}/${TEST_DIR}/pytest_output.log pytest_output.log || echo "No frontend log found."
|
||||
scp ${REMOTE_SERVER}:${BACKEND_TEST_ENV}/${BACKEND_TEST_DIR}/backend_pytest_output.log backend_pytest_output.log || echo "No backend log found."
|
||||
"""
|
||||
}
|
||||
@ -106,22 +109,34 @@ pipeline {
|
||||
emailext(
|
||||
to: 'jassim.mohammed@tech4biz.io',
|
||||
subject: "✅ Jenkins Deployment Successful: Spurrin UI",
|
||||
body: "The deployment and tests completed successfully on ${REMOTE_SERVER}.\n\n${env.BUILD_URL}console"
|
||||
body: "The deployment and backend tests completed successfully on ${REMOTE_SERVER}.\n\n${env.BUILD_URL}console"
|
||||
)
|
||||
}
|
||||
failure {
|
||||
emailext(
|
||||
to: 'jassim.mohammed@tech4biz.io',
|
||||
subject: "❌ Jenkins Deployment Failed: Spurrin UI",
|
||||
body: """Deployment or testing failed on ${REMOTE_SERVER}.
|
||||
|
||||
See full console output:
|
||||
failure {
|
||||
script {
|
||||
def backendErrors = sh(
|
||||
script: "grep -E 'FAIL|ERROR|Exception|Traceback' backend_pytest_output.log || echo 'No errors found.'",
|
||||
returnStdout: true
|
||||
).trim()
|
||||
|
||||
emailext(
|
||||
to: 'jassim.mohammed@tech4biz.io',
|
||||
subject: "❌ Jenkins Deployment Failed: Spurrin UI (Backend Tests)",
|
||||
body: """Deployment or backend testing failed on ${REMOTE_SERVER}.
|
||||
|
||||
⚠️ **Backend Test Errors**:
|
||||
${backendErrors}
|
||||
|
||||
🔍 View full console:
|
||||
${env.BUILD_URL}console
|
||||
""",
|
||||
attachmentsPattern: 'pytest_output.log,backend_pytest_output.log',
|
||||
attachLog: false
|
||||
)
|
||||
attachmentsPattern: 'backend_pytest_output.log',
|
||||
attachLog: false
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
always {
|
||||
echo "🧹 Cleaning Jenkins workspace..."
|
||||
cleanWs()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user