Skip to content
Snippets Groups Projects
Commit 58f073a8 authored by Burhan Akbar's avatar Burhan Akbar
Browse files

Four levels of testing v1

parent bb23938b
No related branches found
No related tags found
No related merge requests found
pipeline {
agent {
docker {
image 'your-java-image'
}
}
services {
// Run MariaDB as a service container
docker {
image 'mariadb:10.11'
args '-e MYSQL_ROOT_PASSWORD=comsc -e MYSQL_DATABASE=healthcare_test'
}
}
agent any
// Define reusable environment variables.
environment {
// The App VMs connection string (user@IP). Replace <APP_VM_IP> with the actual IP.
// The App VM's connection string (user@IP)
APP_VM = "debian@10.72.100.16"
// Credential ID for SSH access to your App VM (the one you added using your openstack_keypair.key).
// Credential ID for SSH access to your App VM
SSH_CRED_ID = "appvm-ssh-cred"
}
......@@ -30,21 +18,17 @@ pipeline {
}
stages {
// Add a stage for manual checkout after cleaning
stage('Checkout') {
steps {
// Add cleanWs() step here to clean before checkout
echo "Cleaning workspace before checkout..."
cleanWs()
echo "Performing manual checkout..."
// Use your actual Git checkout command here if different
// Ensure you specify the correct branch ('ba')
checkout([
$class: 'GitSCM',
branches: [[name: '*/ba']],
userRemoteConfigs: [[
credentialsId: 'gitlab-ssh-key', // Make sure GIT_CRED_ID is defined in Jenkins environment
url: 'git@git.cardiff.ac.uk:c24025433/healthcare.git' // Your Git URL
credentialsId: 'gitlab-ssh-key',
url: 'git@git.cardiff.ac.uk:c24025433/healthcare.git'
]]
])
echo "Checkout complete."
......@@ -53,82 +37,41 @@ pipeline {
stage('Build') {
steps {
// Ensure gradlew is executable
sh 'chmod +x gradlew'
// --- BEGIN DEBUGGING ---
echo "--- Checking source file content AFTER checkout ---"
sh 'cat src/main/resources/static/html/beds.html || echo "Source beds.html not found!"'
echo "-------------------------------------------------"
// More aggressive clean: remove .gradle cache and force task rerun
// build/ is removed by wipeWorkspace() now, but rm -rf .gradle/ is still good
sh '''
rm -rf .gradle/
./gradlew --no-daemon --max-workers=1 clean build --rerun-tasks
'''
// --- MORE DEBUGGING ---
echo "--- Checking JAR file content AFTER build ---"
sh '''
echo "Listing JAR contents for beds.html:"
jar tf build/libs/HealthCare-0.0.1-SNAPSHOT.jar | grep beds.html || echo "beds.html not found in JAR!"
echo "Attempting to extract beds.html from JAR to current directory:"
# Extract just the specific file, letting jar create subdirs if needed in the workspace
jar xf build/libs/HealthCare-0.0.1-SNAPSHOT.jar BOOT-INF/classes/static/html/beds.html || echo "Failed to extract beds.html using jar xf!"
echo "Content of extracted beds.html:"
# Cat the file from its expected location relative to workspace root
cat BOOT-INF/classes/static/html/beds.html || echo "Failed to cat extracted beds.html!"
# Clean up the extracted structure from the workspace
rm -rf BOOT-INF
'''
echo "---------------------------------------------"
// --- END DEBUGGING ---
sh './gradlew --no-daemon clean build --rerun-tasks'
}
}
stage('Test') {
steps {
// Exclude repository tests that need a database
sh './gradlew test --exclude "**/mapper/**"'
}
}
stage('Optional UI Tests') {
steps {
// Run Selenium UI tests. If not configured (or if they fail), the || true ensures the build continues.
// Run UI tests but don't fail the build if they fail
sh './gradlew test -Dtest="*Selenium*Test" || true'
}
}
stage('Deploy to App VM') {
steps {
// Use SSH credentials to securely execute commands on the App VM.
sshagent([env.SSH_CRED_ID]) {
// Copy the built JAR, the docker-compose.yml file, and the Dockerfile over to the App VM.
sh """
scp build/libs/HealthCare-0.0.1-SNAPSHOT.jar ${APP_VM}:~/healthcare/
scp docker-compose.yml ${APP_VM}:~/healthcare/
scp Dockerfile ${APP_VM}:~/healthcare/
"""
// SSH into the App VM and run the deployment commands. Reverted to remove --no-cache and --force-recreate.
sh """
ssh ${APP_VM} '
echo "Changing directory to ~/healthcare"
cd ~/healthcare &&
echo "Attempting docker-compose down..."
# Added --remove-orphans just in case, though likely not needed here
/usr/bin/docker-compose down --remove-orphans || echo "Compose down failed or had nothing to do."
echo "Attempting docker system prune..."
docker system prune -f && echo "Prune successful." || echo "Prune failed."
echo "Attempting to remove existing application image..."
# Force remove the specific image to bypass cache
docker system prune -f || echo "Prune failed."
docker rmi healthcare_healthcare_01 || echo "Image removal failed or image not found."
echo "Attempting docker-compose up with --build..."
/usr/bin/docker-compose -f docker-compose.yml up -d --build && echo "Compose up command issued." || echo "Compose up command failed."
/usr/bin/docker-compose -f docker-compose.yml up -d --build || echo "Compose up command failed."
'
"""
}
......@@ -138,7 +81,6 @@ pipeline {
post {
always {
// Clean the workspace after the job is complete.
cleanWs()
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment