-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
107 lines (103 loc) · 3.62 KB
/
Jenkinsfile
File metadata and controls
107 lines (103 loc) · 3.62 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
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
#!/usr/bin/env groovy
pipeline {
agent any
tools {
maven 'Maven'
jdk 'JDK'
}
environment {
DEPLOYMENT_HOSTNAME = '99.81.60.98'
}
options {
buildDiscarder(logRotator(numToKeepStr: '10', artifactNumToKeepStr: '5'))
}
stages {
stage('Build') {
steps {
dir('.') {
sh "mvn -B clean install -DskipTests"
}
}
}
stage('Test') {
steps {
dir('.') {
script {
try {
sh "mvn -B test -Dmaven.test.failure.ignore=true"
} finally {
junit '**/target/surefire-reports/*.xml'
}
}
}
}
}
stage('Deploy') {
when {
expression { currentBuild.currentResult == 'SUCCESS' }
}
steps {
sshPublisher(
publishers: [
sshPublisherDesc(
configName: 'AWS NoC',
transfers:[
sshTransfer(
excludes: '',
execCommand: "systemctl restart twitter-bubbles@${env.BRANCH_NAME}",
execTimeout: 120000,
flatten: false,
makeEmptyDirs: false,
noDefaultExcludes: false,
patternSeparator: '[, ]+',
remoteDirectory: "${env.BRANCH_NAME}",
remoteDirectorySDF: false,
removePrefix: 'server/target',
sourceFiles: 'server/target/*.jar'
)
],
usePromotionTimestamp: false,
useWorkspaceInPromotion: false,
verbose: true
)
]
)
}
}
}
post {
always{
script {
// workaround for null currentBuild.result when the result is SUCCESS
currentBuild.result = currentBuild.currentResult
}
notifyStatusChangedViaEmail("${currentBuild.result}")
}
success {
sendEmail("${currentBuild.result}", true)
}
}
}
def notifyStatusChangedViaEmail(buildStatus) {
if (buildStatus != 'SUCCESS') {
sendEmail(buildStatus)
}
}
def sendEmail(buildStatus, deployment=false){
def emailBody = "Email from Jenkins.<br>\nProject: ${env.JOB_NAME}<br>\nBuild Number: ${env.BUILD_NUMBER}<br>\nURL of build: ${env.BUILD_URL}"
if (deployment) {
def props = readProperties file: 'server/src/main/resources/application.properties'
def port = props['server.port']
def contextPath = props['server.servlet.context-path']
def applicationUrl = "http://${env.DEPLOYMENT_HOSTNAME}:${port}${contextPath}"
emailBody += "<br>\nApplication URL: ${applicationUrl}" +
"<br>\nApplication info: ${applicationUrl}/actuator/info"
}
emailext (
subject: "Jenkins ${env.JOB_NAME} is ${buildStatus}",
body: "${emailBody}",
recipientProviders: [
[$class: 'DevelopersRecipientProvider']
]
)
}