-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjenkins
More file actions
executable file
·54 lines (48 loc) · 1.55 KB
/
jenkins
File metadata and controls
executable file
·54 lines (48 loc) · 1.55 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
pipeline {
agent any
environment {
DOCKER_COMPOSE_FILE = 'docker-compose.yml'
SERVICE_NAME = 'smart-shell-angular'
}
stages {
stage('Checkout') {
steps {
git branch: 'main', url: 'https://github.com/luis122448/smart-shell-angular'
}
}
stage('Stop Container') {
steps {
script {
def containerExists = sh(script: "docker ps -q -f name=${SERVICE_NAME}", returnStatus: true)
if (containerExists == 0) {
sh "docker-compose -f ${DOCKER_COMPOSE_FILE} stop ${SERVICE_NAME}"
}
}
}
}
stage('Build') {
steps {
sh "docker-compose -f ${DOCKER_COMPOSE_FILE} build ${SERVICE_NAME}"
}
}
stage('Run') {
steps {
sh "docker-compose -f ${DOCKER_COMPOSE_FILE} up -d ${SERVICE_NAME}"
}
}
}
post {
success {
echo 'Deployment was successful!'
}
failure {
script {
def previousCommit = sh(script: "git rev-parse HEAD~1", returnStdout: true).trim()
sh "git reset --hard ${previousCommit}"
sh "docker-compose -f ${DOCKER_COMPOSE_FILE} build ${SERVICE_NAME}"
sh "docker-compose -f ${DOCKER_COMPOSE_FILE} up -d ${SERVICE_NAME}"
error('Deployment failed. Rolled back to previous commit.')
}
}
}
}