forked from revaturelabs/client-engagement-portal-back
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
77 lines (75 loc) · 1.63 KB
/
Jenkinsfile
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
pipeline {
agent any
environment{
JENKINS_NODE_COOKIE = 'dontkillmeplease'
PORT=9011
}
stages {
stage('Destroy Old Server') {
steps {
script {
try {
// kill any running instances
sh 'kill $(lsof -t -i:$PORT)'
} catch (all) {
// if it fails that should mean a server wasn't already running
echo 'No server was already running'
}
}
}
}
stage('Install maven dependencies') {
steps {
//clean install maven
sh 'mvn install'
}
}
stage ('Clean & Package') {
steps {
sh 'mvn clean package'
}
}
/*
* Tries to remove an existing Docker Container named cep
*/
stage ('Remove Docker Container') {
steps {
script {
try {
sh 'docker rm -f cep'
} catch (all) {
echo 'Docker Container does not exist'
}
}
}
}
/*
* Deletes Extra images that has no container
*/
stage ('Delete Docker Image') {
steps {
sh 'docker image prune -a -f'
}
}
stage ('Docker Build') {
steps {
sh 'docker build -t tyronev/ce-portal:v1 .'
}
}
stage ('Docker Run') {
steps {
sh 'docker run -p 9011:9011 --name cep -it -d tyronev/ce-portal:v1'
}
}
stage ('Docker Log') {
steps {
sh 'nohup docker logs -f cep > /home/ec2-user/.jenkins/workspace/CEP-Back/logs/application.log &';
}
}
stage ('Docker Check Containers') {
steps {
sh 'docker ps -a'
}
}
}
}