-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
118 lines (112 loc) · 4.99 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
pipeline {
agent any
options {
gitLabConnection('in gitlab')
}
tools {
maven 'Maven'
jdk 'JDK 8'
}
stages {
// Run unit test in all cases
stage('Unit Test') {
steps {
gitlabCommitStatus('Unit Test') {
echo BRANCH_NAME
sh 'mvn -Dmaven.test.failure.ignore=true clean test site'
jacoco()
recordIssues(tools: [checkStyle(), findBugs(useRankAsPriority: true), pmdParser()])
}
}
post {
always {
junit 'target/surefire-reports/**/*.xml'
}
}
}
// Build involves integration tests and upload to artifactory
stage('Build') {
when {
anyOf {
branch 'master'
branch 'development'
}
}
steps {
gitlabCommitStatus('Unit Test') {
echo BRANCH_NAME
sh 'mvn -Dbuild.number=$BUILD_NUMBER clean install site'
}
}
post {
always {
junit 'target/failsafe-reports/**/*.xml'
}
success {
archiveArtifacts artifacts: 'target/*.jar', fingerprint: true
}
}
}
stage('Deploy on staging') {
when {
anyOf {
branch 'master'
branch 'development'
}
}
steps {
gitlabCommitStatus('Deploy on staging') {
script {
def name = sh script: 'mvn help:evaluate -Dexpression=project.name | grep -v "^\\[" | tr -d \'\\n\'', returnStdout: true
def version = sh script: 'mvn help:evaluate -Dexpression=project.version | grep -v "^\\[" | tr -d \'\\n\'', returnStdout: true
def filename = name + "-" + version + ".jar"
echo filename
withCredentials([sshUserPrivateKey(credentialsId: '13e88844-d8e9-46dc-b6d0-196b13b9dc42', keyFileVariable: 'identity', passphraseVariable: 'passphrase', usernameVariable: 'userName')]) {
def remote = [:]
remote.user = userName
remote.identityFile = identity
remote.passphrase = passphrase
remote.name = '193.196.55.217'
remote.host = '193.196.55.217'
remote.allowAnyHosts = true
sshPut remote: remote, from: "target/" + filename, into: '/opt/coffeeshop'
sshCommand remote: remote, command: 'chmod 744 /opt/coffeeshop/' + filename
sshCommand remote: remote, command: 'ln -s -f /opt/coffeeshop/' + filename + ' /opt/coffeeshop/shop-ui.jar'
sshCommand remote: remote, command: 'systemctl restart coffeeshop', sudo: true
}
}
}
}
}
stage('Deploy on production') {
when {
anyOf {
branch 'master'
}
}
steps {
gitlabCommitStatus('Deploy on production') {
script {
def name = sh script: 'mvn help:evaluate -Dexpression=project.name | grep -v "^\\[" | tr -d \'\\n\'', returnStdout: true
def version = sh script: 'mvn help:evaluate -Dexpression=project.version | grep -v "^\\[" | tr -d \'\\n\'', returnStdout: true
def filename = name + "-" + version + ".jar"
echo filename
withCredentials([sshUserPrivateKey(credentialsId: '13e88844-d8e9-46dc-b6d0-196b13b9dc42', keyFileVariable: 'identity', passphraseVariable: 'passphrase', usernameVariable: 'userName')]) {
def remote = [:]
remote.user = userName
remote.identityFile = identity
remote.passphrase = passphrase
remote.name = '193.196.52.226'
remote.host = '193.196.52.226'
remote.allowAnyHosts = true
sshPut remote: remote, from: "target/" + filename, into: '/opt/coffeeshop'
sshCommand remote: remote, command: 'chmod 744 /opt/coffeeshop/' + filename
sshCommand remote: remote, command: 'ln -s -f /opt/coffeeshop/' + filename + ' /opt/coffeeshop/shop-ui.jar'
sshCommand remote: remote, command: 'systemctl restart coffeeshop', sudo: true
}
}
}
}
}
}
}