This repository was archived by the owner on May 17, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
90 lines (77 loc) · 2.33 KB
/
Jenkinsfile
File metadata and controls
90 lines (77 loc) · 2.33 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
pipeline {
agent {
docker {
image 'maven:3-jdk-8'
args '--volumes-from jenkins_mvn_1 -v /var/run/docker.sock:/var/run/docker.sock'
}
}
environment {
NEXUS_PASSWORD = credentials('NEXUS_PASSWORD')
NEXUS_AUTH = credentials('NEXUS_AUTH')
SONAR_PASSWORD = credentials('SONAR_PASSWORD')
}
stages {
stage('env') {
steps {
notifyStarted()
sh 'printenv'
}
}
stage('build') {
steps {
sh 'mvn -s $MAVEN_SETTINGS -B clean install'
}
}
stage('quality') {
steps {
sh 'mvn -s $MAVEN_SETTINGS -B sonar:sonar'
}
}
stage('deploy') {
steps {
sh 'mvn -s $MAVEN_SETTINGS -B deploy'
}
}
}
post {
always {
junit '**/target/surefire-reports/*.xml'
}
success {
notifySuccess()
}
unstable {
notifyUnstable()
}
failure {
notifyFailed()
}
}
}
def notifyBuild(String buildStatus = 'STARTED', String colorCode = '#5492f7', String notify = '') {
def project = 'jonah'
def channel = "ci_invest"
def base = "https://bitbucket.org/committed/${project}/commits/"
def commit = sh(returnStdout: true, script: 'git log -n 1 --format="%H"').trim()
def link = "${base}${commit}"
def shortCommit = commit.take(6)
def title = sh(returnStdout: true, script: 'git log -n 1 --format="%s"').trim()
def subject = "<${link}|${shortCommit}> ${title}"
def summary = "${buildStatus}: Job <${env.RUN_DISPLAY_URL}|${env.JOB_NAME} [${env.BUILD_NUMBER}]>\n${subject} ${notify}"
slackSend (channel: "#${channel}", color: colorCode, message: summary)
}
def author() {
return sh(returnStdout: true, script: 'git log -n 1 --format="%an" | awk \'{print tolower($1);}\'').trim()
}
def notifyStarted() {
notifyBuild()
}
def notifySuccess() {
notifyBuild('SUCCESS', 'good')
}
def notifyUnstable() {
notifyBuild('UNSTABLE', 'warning', "\nAuthor: @${author()} <${RUN_CHANGES_DISPLAY_URL}|Changelog>")
}
def notifyFailed() {
notifyBuild('FAILED', 'danger', "\nAuthor: @${author()} <${RUN_CHANGES_DISPLAY_URL}|Changelog>")
}