-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
115 lines (109 loc) · 4.65 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
pipeline {
agent any
options {
buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '10', daysToKeepStr: '', numToKeepStr: '10')
}
environment {
PROJECT_ROOT = 'D:\\Testing\\NesmaProject\\Estate-Book'
WORKSPACE_WINDOWS = 'C:\\ProgramData\\Jenkins\\.jenkins\\workspace\\EstateBookPipeline'
WORKSPACE = 'C:/ProgramData/Jenkins/.jenkins/workspace/EstateBookPipeline'
ALLURE_REPORT = "allure-report/"
ALLURE_REPORT_HTML = "index.html"
ALLURE_RESULTS = "allure-results"
TARGET_FOLDER = 'target'
SUREFIRE_REPORTS = '/surefire-reports'
HTML_REPORT = '/emailable-report.html'
EMAIL_RECIPIENT = '[email protected]'
}
stages {
stage('Cleanup') {
steps {
script {
echo "Starting 'Cleanup' Stage!!"
def targetPath = "${WORKSPACE_WINDOWS}\\${TARGET_FOLDER}"
if (fileExists(targetPath)) {
// Delete the target folder
bat "rmdir /s /q ${targetPath}"
echo "Target directory removed successfully : ${targetPath}"
} else {
echo "Target directory does not exist at : ${targetPath}. No cleanup needed."
}
def allurePath = "${WORKSPACE_WINDOWS}\\${ALLURE_RESULTS}"
if (fileExists(allurePath)) {
// Delete the target folder
bat "rmdir /s /q ${allurePath}"
echo "Allure-results directory removed successfully : ${allurePath}"
} else {
echo "Allure-results directory does not exist at : ${allurePath}. No cleanup needed."
}
}
}
}
stage('Build') {
steps {
script {
echo "Starting 'Build' Stage!!"
bat 'mvn install -DskipTests'
}
}
}
stage('Test') {
steps {
script {
echo "Starting 'Test' Stage!!"
def testsToRun = ["SignInTest", "TypeFiltrationTest"]
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
testsToRun.each {
test ->
echo "Starting test ${test}"
bat "mvn clean test -Dtest=\"${test}\""
}
}
// bat 'mvn clean test -Dtest="SignInTest"'
}
}
}
stage('Generate Allure Report') {
steps {
script {
ws("${PROJECT_ROOT}") {
allure([
includeProperties: false,
jdk : '',
properties : [],
reportBuildPolicy: 'ALWAYS',
results : [[path: 'allure-results']]
])
}
}
}
}
}
post {
always {
// stage('Mail Distribution') {
// steps {
script {
echo "Starting 'Mail Distribution' Stage!!"
bat "C:/Users/Agami/scoop/apps/allure/2.25.0/bin/allure.bat generate --single-file allure-results --clean"
def allureAttachment = "${ALLURE_REPORT}"
def allureReportPath = "${ALLURE_REPORT}${ALLURE_REPORT_HTML}"
def testNGAttachment = "${TARGET_FOLDER}${SUREFIRE_REPORTS}${HTML_REPORT}"
def testNGReportContent = readFile(file: testNGAttachment)
if (fileExists(allureAttachment) || fileExists(testNGAttachment)) {
emailext(
subject: "Allure Results",
body: "Please find the attached test results. \n\n${testNGReportContent}",
to: "${EMAIL_RECIPIENT}",
mimeType: 'text/html',
attachmentsPattern: "${allureAttachment},${testNGAttachment}"
)
} else {
echo "File doesn't exist at: ${allureAttachment},${testNGAttachment}"
}
}
// }
// }
}
}
}