-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
62 lines (54 loc) · 1.8 KB
/
Jenkinsfile
File metadata and controls
62 lines (54 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
pipeline {
agent {
docker {
image 'konarklohat2611/typesmart-jenkins:latest'
args '-v /var/run/docker.sock:/var/run/docker.sock'
}
}
environment {
PROJECT_NAME = 'typesmart-editor'
BRANCH_NAME = "${env.GIT_BRANCH ? env.GIT_BRANCH.replaceFirst(/^origin\//, '') : 'dev'}"
}
stages {
stage('Clone') {
steps {
echo "Cloning branch: ${env.BRANCH_NAME}"
checkout scm
}
}
stage('Run Unit Tests') {
steps {
dir('suggestion-service') {
echo "Running unit tests for suggestion-service"
sh 'mvn test'
junit 'target/surefire-reports/*.xml'
}
}
}
stage('Build and Deploy') {
steps {
script {
def branch = env.BRANCH_NAME
def composeFile = "docker-compose.${branch}.yml"
if (!fileExists(composeFile)) {
error "No compose file found for branch: ${branch}"
}
echo "Building and deploying using: ${composeFile}"
sh """
docker compose -f docker-compose.yml -f ${composeFile} down || true
docker compose -f docker-compose.yml -f ${composeFile} build
docker compose -f docker-compose.yml -f ${composeFile} up -d
"""
}
}
}
}
post {
success {
echo "CI/CD pipeline completed successfully for branch: ${env.BRANCH_NAME}"
}
failure {
echo "CI/CD pipeline failed for branch: ${env.BRANCH_NAME}"
}
}
}