-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
79 lines (71 loc) · 2.4 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
enum CommitState {
ERROR, FAILURE, PENDING, SUCCESS
CommitState() {}
}
static String buildStatusMessage(Object build, CommitState state) {
switch (state) {
case CommitState.ERROR:
return "Build $build.displayName errored in ${build.durationString.minus(' and counting')}"
case CommitState.FAILURE:
return "Build $build.displayName failed in ${build.durationString.minus(' and counting')}"
case CommitState.SUCCESS:
return "Build $build.displayName succeeded in ${build.durationString.minus(' and counting')}"
default:
return "Build $build.displayName in progress"
}
}
void githubStatus(CommitState state) {
def repoUrl = scm.userRemoteConfigs[0].url
def message = buildStatusMessage(currentBuild, state)
step([
$class: "GitHubCommitStatusSetter",
reposSource: [$class: "ManuallyEnteredRepositorySource", url: repoUrl],
errorHandlers: [[$class: "ChangingBuildStatusErrorHandler", result: "UNSTABLE"]],
statusResultSource: [
$class : "ConditionalStatusResultSource",
results: [[$class: "AnyBuildResult", message: message, state: state.name()]]
]
])
}
pipeline {
agent any
options { timestamps() }
triggers { githubPush() }
stages {
stage('Clean') {
steps {
githubStatus CommitState.PENDING
println "Kind: ${currentBuild.changeSets[0].kind}"
println "Message: ${currentBuild.changeSets[0].items[0].msg}"
sh 'git clean -xdff'
}
}
stage('Build') {
steps {
sh 'git log -1 --pretty=%s'
sh 'mvn test-compile'
}
}
stage('Tests') {
steps {
sh 'mvn jacoco:prepare-agent surefire:test'
}
}
stage('Test Reports') {
steps {
sh 'mvn jacoco:report'
}
}
}
post {
always {
archiveArtifacts '**/target/surefire-reports/*'
archiveArtifacts '**/target/site/jacoco/**'
junit '**/target/surefire-reports/*.xml'
step([$class: 'JacocoPublisher'])
//cleanWs()
}
success { githubStatus CommitState.SUCCESS }
unsuccessful { githubStatus CommitState.FAILURE }
}
}