forked from glazfehler/java-junit-sample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
89 lines (70 loc) · 2.54 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
pipeline {
agent any
environment {
sonarAnalyzeResult = 'FAILURE'
testRunResult = 'FAILURE'
}
stages {
stage ('Checkout scm') {
steps {
script {
checkout scm: [$class: 'GitSCM', branches: [[name: '*/master']], userRemoteConfigs: [[url: 'https://github.com/mike-podolskiy90/java-junit-sample.git/']]]
}
}
}
stage('SonarQube analysis') {
steps {
script {
sonarAnalyzeResult = build(job: "task7-sonar-analyze", propagate: false).result
echo "First job result: $sonarAnalyzeResult"
if(sonarAnalyzeResult == 'FAILURE') {
currentBuild.result = 'UNSTABLE'
}
}
}
}
stage('Tests run') {
steps {
script {
testRunResult = build(job: "task7-test-run", propagate: false).result
echo "Second job result: $testRunResult"
if(testRunResult == 'FAILURE') {
currentBuild.result = 'UNSTABLE'
}
}
}
}
stage('Check result') {
steps {
script {
if(sonarAnalyzeResult == 'UNSTABLE' && testRunResult == 'UNSTABLE') {
currentBuild.result = 'FAILURE'
}
if (currentBuild.currentResult == 'FAILURE') { // Other values: SUCCESS, UNSTABLE
def checkLastCommit = bat (
script: "git show -s --format=short HEAD",
returnStdout: true
)
echo "$checkLastCommit"
def authorEmail = bat (
script: "git show -s --format='%%ae' HEAD",
returnStdout: true
).split('\r\n')[2].trim()
echo "$authorEmail"
echo "The last commit was written by ${authorEmail}."
// Send an email only if the build status has changed from green/unstable to red
emailext subject: '$DEFAULT_SUBJECT',
body: '$DEFAULT_CONTENT',
recipientProviders: [
[$class: 'CulpritsRecipientProvider'],
[$class: 'DevelopersRecipientProvider'],
[$class: 'RequesterRecipientProvider']
],
replyTo: '$DEFAULT_REPLYTO',
to: "${authorEmail}"
}
}
}
}
}
}