forked from kstateome/canvas-api
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
134 lines (117 loc) · 3.87 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
@Library('jenkins-shared-libs')
import edu.ksu.jenkins.*
pipeline {
agent any
environment {
testDeploy = "${BRANCH_NAME}"
regexIgnore = ".*maven-release-plugin.*;.*skipJenkins.*"
}
tools {
maven "Maven 3.5"
jdk "Java 8"
}
stages {
stage('Build') {
steps {
script {
if (shouldIgnoreCommit(env.regexIgnore.split(';'))) {
error "Ignoring commit"
}
}
sh 'mvn clean package -DskipTests'
}
post {
always {
script {
if (shouldIgnoreCommit(env.regexIgnore.split(';'))) {
currentBuild.result = 'NOT_BUILT'
}
}
}
}
}
stage('Unit Tests') {
steps {
sh 'mvn test'
}
post {
always {
junit '**/target/surefire-reports/*.xml'
}
failure {
itsChat Constants.DEFAULT_CHANNEL, "${env.JOB_NAME} had unit test failures on branch ${env.BRANCH_NAME} \nRecent Changes - ${getChangeString(10)}\nBuild: ${BUILD_URL}"
}
unstable {
itsChat Constants.DEFAULT_CHANNEL, "${env.JOB_NAME} had unit test failures on branch ${env.BRANCH_NAME} \nRecent Changes - ${getChangeString(10)}\nBuild: ${BUILD_URL}"
}
changed {
script {
if (currentBuild.result == null || currentBuild.result == 'SUCCESS') {
itsChat Constants.DEFAULT_CHANNEL, "${env.JOB_NAME} now has passing unit tests on branch ${env.BRANCH_NAME} \nRecent Changes - ${getChangeString(10)}\nBuild: ${BUILD_URL}"
}
}
}
}
}
stage('Sonar') {
when {
branch 'master'
}
steps {
sh 'mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install'
sh "mvn sonar:sonar -P sonar -Dsonar.branch=${env.branch_name}"
}
}
stage('Maven Site') {
when { branch 'master' }
steps {
sh 'mvn site-deploy'
}
post {
success {
itsChat 'javabuilds', "Successfully generated Maven site documentation for canvas-api: https://jenkins.ome.ksu.edu/maven-site/canvas-api/"
}
}
}
}
post {
always {
deleteDir()
}
}
}
@NonCPS
def version() {
pom = readMavenPom file: 'pom.xml'
pom.version
}
def shouldIgnoreCommit(regexIgnoreList) {
def lastCommit = sh (script: 'git log --pretty=oneline | head -n 1', returnStdout: true)
// For loop is used because [].each is not serializable
for (int i = 0; i < regexIgnoreList.size(); i++) {
if (lastCommit =~ /${regexIgnoreList[i]}/) {
return true
}
}
return false
}
@NonCPS
def getChangeString(maxMessages) {
MAX_MSG_LEN = 100
COMMIT_HASH_DISPLAY_LEN = 7
def changeString = ""
def changeLogSets = currentBuild.changeSets
for (int i = 0; i < changeLogSets.size(); i++) {
def entries = changeLogSets[i].items
for (int j = 0; j < entries.length && i + j < maxMessages; j++) {
def entry = entries[j]
truncated_msg = entry.msg.take(MAX_MSG_LEN)
commitHash = entry.commitId.take(COMMIT_HASH_DISPLAY_LEN)
changeString += "${commitHash}... - ${truncated_msg} [${entry.author}]\n"
}
}
if (!changeString) {
changeString = " There have not been changes since the last build"
}
return changeString
}