forked from foglamp/FogLAMP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
141 lines (128 loc) · 5.73 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
135
136
137
138
139
140
141
node {
// allow user to run job with all tests, only python tests, only doc tests
def choice_test_all = 'all'
def choice_test_doc = 'doc-build-tests'
def choice_test_python = 'python-unit-tests' // pointing to src/python/tests
// adding job parameters and build triggers twice a day (5AM and 2PM UTC time) within jenkinsfile
properties([
parameters([
stringParam(
defaultValue: '[email protected]:foglamp/FogLAMP.git',
description: 'Repository which you want to use in this (upstream) job',
name: 'repo_url'
),
stringParam(
defaultValue: 'develop',
description: 'The git branch you would like to build with',
name: 'branch'
),
choice(
choices: "${choice_test_all}\n${choice_test_doc}\n${choice_test_python}",
description: "run tests as per your choice",
name: 'suite'
)
]),
pipelineTriggers([cron('H(0-0) 5,14 * * *')])
])
try{
notifyBuild('STARTED')
// Clean workspace before build starts
stage ("Clean Workspace"){
deleteDir()
}
// Clone git repo
stage ("Clone Git Repo"){
checkout([$class: 'GitSCM', branches: [[name: "${branch}"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CheckoutOption', timeout: 20], [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: true, timeout: 20]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'jenkins', refspec: "+refs/heads/${branch}:refs/remotes/origin/${branch}", url: '${repo_url}']]])
}
// echo git branch, commit hash id, workspace dir for debugging
def gitBranch = branch.trim()
def gitCommit = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
def workspace_dir = sh(returnStdout: true, script: 'pwd').trim()
// xterm ANSI colormap has GREEN foreground color
// error ANSI colormap has RED foreground color
ansiColor('xterm'){
echo "git branch is ${gitBranch}"
echo "git commit is $gitCommit"
echo "Workspace is ${workspace_dir}"
}
// lint checking and see report from Pylint warnings plugin
stage ("Lint"){
dir ('src/python/'){
sh '''#!/bin/bash -l
./build.sh -l
'''
ansiColor('xterm'){
warnings([canResolveRelativePaths: false, canRunOnFailed: true, categoriesPattern: '', defaultEncoding: '', excludePattern: '', healthy: '', includePattern: '', messagesPattern: '', parserConfigurations: [[parserName: 'PyLint', pattern: 'pylint_*.log']], unHealthy: ''])
}
}
}
// test report on the basis of suite and see report from Allure report plugin &
// see test code coverage report from Coverage report Plugin only when suite choice_test_all and choice_test_python
stage ("Test Report"){
try{
dir ('src/python/'){
if (suite == "${choice_test_all}"){
echo "${choice_test_all}"
sh '''#!/bin/bash -l
./build.sh -p
./build.sh --doc-build-test
'''
currentBuild.result = "SUCCESSFUL"
}else if (suite == "${choice_test_doc}"){
echo "${choice_test_doc}"
sh '''#!/bin/bash -l
./build.sh --doc-build-test
'''
currentBuild.result = "SUCCESSFUL"
}else if (suite == "${choice_test_python}"){
echo "${choice_test_python}"
sh '''#!/bin/bash -l
./build.sh -p
'''
currentBuild.result = "SUCCESSFUL"
}
}
}
finally{
ansiColor('xterm'){
if (suite != "${choice_test_doc}"){
stage ("Test Coverage Report"){
dir ('src/python/'){
step([$class: 'CoberturaPublisher', autoUpdateHealth: false, autoUpdateStability: false, coberturaReportFile: 'coverage.xml', failNoReports: false, failUnhealthy: false, failUnstable: false, maxNumberOfBuilds: 0, onlyStable: false, sourceEncoding: 'ASCII', zoomCoverageChart: false])
}
}
}
allure([includeProperties: false, jdk: '', properties: [], reportBuildPolicy: 'ALWAYS', results: [[path: 'allure/']]])
}
// Success of failure, always send notifications
if(currentBuild.result == 'SUCCESSFUL'){
notifyBuild(currentBuild.result)
}
}
}
}catch (e){
// If there was an exception thrown, the build failed
currentBuild.result = "FAILED"
notifyBuild(currentBuild.result)
throw e
}
}
def notifyBuild(String buildStatus = 'STARTED'){
// build status of null means successful
buildStatus = buildStatus ?: 'SUCCESSFUL'
// Default values
def color = 'RED'
def colorCode = '#FF0000'
def subject = "${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'"
def summary = "${subject} (${env.BUILD_URL})"
// Override default values based on build status
if (buildStatus == 'STARTED'){
color = 'YELLOW'
colorCode = '#FFFF00'
} else if (buildStatus == 'SUCCESSFUL'){
color = 'GREEN'
colorCode = '#00FF00'
}
// Send notifications
slackSend (color: colorCode, message: summary)
}