-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
85 lines (82 loc) · 2.92 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
78
79
80
81
82
83
84
85
pipeline {
agent any
environment {
registryCredential = 'docker-key'
dockerImage = ''
}
stages {
stage('Change File') {
steps {
script {
def applicationYmlPath = './src/main/resources/application.yml'
def oAuthConstantsPath = './src/main/java/swm_nm/morandi/auth/constants/OAuthConstants.java'
if (fileExists(applicationYmlPath)) {
sh "rm ${applicationYmlPath}"
}
if (fileExists(oAuthConstantsPath)) {
sh "rm ${oAuthConstantsPath}"
}
sh "cp /var/jenkins_home/application.yml ${applicationYmlPath}"
sh "cp /var/jenkins_home/OAuthConstants.java ${oAuthConstantsPath}"
}
}
}
stage('Bulid Gradle') {
steps {
echo 'Bulid Gradle'
sh './gradlew clean bootJar'
}
post {
failure {
error 'This pipeline stops here...'
}
}
}
stage('Bulid Docker') {
steps {
echo 'Bulid Docker'
script {
dockerImage = docker.build "${image}"
}
}
post {
failure {
error 'This pipeline stops here...'
}
}
}
stage('Push Docker') {
steps {
echo 'Push Docker'
script {
docker.withRegistry('', registryCredential) {
dockerImage.push("latest")
}
}
}
post {
failure {
error 'This pipeline stops here...'
}
}
}
stage('Deploy') {
steps {
echo 'SSH'
script {
def imageExists = sh(returnStdout: true, script: "docker images -q ${image}").trim()
if (imageExists) {
sh "docker rmi ${image}"
}
sshagent(['server-key']) {
sh "ssh -o StrictHostKeyChecking=no [email protected] 'docker stop morandi-container || true'"
sh "ssh -o StrictHostKeyChecking=no [email protected] 'docker rm morandi-container || true'"
sh "ssh -o StrictHostKeyChecking=no [email protected] 'docker rmi aj4941/morandi-server || true'"
sh "ssh -o StrictHostKeyChecking=no [email protected] 'docker pull aj4941/morandi-server'"
sh "ssh -o StrictHostKeyChecking=no [email protected] 'docker run -d -p 8080:8080 --name morandi-container aj4941/morandi-server sleep infinity'"
}
}
}
}
}
}