Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Team6-Digital Insight for Health
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chen Liang
Team6-Digital Insight for Health
Commits
58f073a8
Commit
58f073a8
authored
4 months ago
by
Burhan Akbar
Browse files
Options
Downloads
Patches
Plain Diff
Four levels of testing v1
parent
bb23938b
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Jenkinsfile
+10
-68
10 additions, 68 deletions
Jenkinsfile
with
10 additions
and
68 deletions
Jenkinsfile
+
10
−
68
View file @
58f073a8
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 VM
’
s 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
()
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment