forked from blueriq/blueriq-material
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
186 lines (171 loc) · 6.68 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!groovy
boolean isMaster = BRANCH_NAME == 'master'
String triggerCron = isMaster ? "H 13 * * 7" : ""
properties([
[
$class : 'BuildDiscarderProperty',
strategy: [$class: 'LogRotator', numToKeepStr: '5']
],
pipelineTriggers([
cron(triggerCron)
]),
parameters([
booleanParam(
name: 'deploySnapshot',
defaultValue: false,
description: 'Select if you want to deploy a snapshot to artifactory.'
),
booleanParam(
name: 'isRelease',
defaultValue: false,
description: 'Select if you want to do a release build.'
),
string(
name: 'releaseVersion',
defaultValue: '1.0.x',
description: 'In case of a release-build please provide the release version.'
),
string(
name: 'developmentVersion',
defaultValue: '1.0.x-SNAPSHOT',
description: 'In case of a release-build please provide the next development version.'
),
string(
name: 'communityHost',
defaultValue: '',
description: 'In case of a release-build please provide the hostname of the server where to publish the community documentation to.'
),
string(
name: 'communityUser',
defaultValue: '',
description: 'In case of a release-build please provide the username for the server where to publish the community documentation to.'
),
string(
name: 'communityPass',
defaultValue: '',
description: 'In case of a release-build please provide the password for the server where to publish the community documentation to.'
)
])
])
node {
try {
env.JAVA_HOME = tool 'jdk1.8.0_121'
def mvnHome = tool "apache-maven-3.5.4"
env.PATH = "${env.JAVA_HOME}\\bin;${env.PATH};${mvnHome}\\bin;${env.NODEJS_PATH}\""
env.SASS_BINARY_PATH = env.SASS_BINDING_PATH
env.CHROME_BIN = env.CHROME_67_0_3396_99;
stage('checkout') {
checkout scm
}
stage('install') {
bat 'node -v'
bat 'yarn -v'
bat 'yarn install'
bat 'yarn ng:version'
}
stage('verify & build') {
parallel(
'test': {
def result = bat([returnStdout: true, script: "yarn verify"]);
println result;
// Unfortunatly it is needed to check if the coverage is not met because the coverage-reporter always exits with error_level=0
// so we need to make the build unstable manually. you can check the coverage html result to see where it is failing
if (result.contains('ERROR [reporter.coverage-istanbul]:') || result.contains('WARN [reporter.coverage-istanbul]:')) {
println 'Unit tests do not meet coverage thresholds, setting the build to unstable';
currentBuild.result = 'UNSTABLE';
}
},
'tslint': {
// tslint
bat 'node_modules\\.bin\\tslint -c src/tslint.json -t checkstyle -p src/tsconfig.app.json -p src/tsconfig.spec.json -o tslint_results_checkstyle.xml'
},
'sass-lint': {
// sass-lint
bat 'node_modules\\.bin\\sass-lint -f checkstyle --verbose --config sass-lint.yml src/**/*.scss -o sasslint_results_checkstyle.xml'
},
'build': {
if (!params.isRelease) { // maven release executes the yarn build also
bat "yarn build --progress=false"
}
}
);
}
if (params.deploySnapshot) {
stage('deploy snapshot') {
bat "mvn clean deploy"
}
} else if (params.isRelease) {
// stage('increment version for release') {
// bat "yarn version:increment ${params.releaseVersion}"
// }
stage('release') {
bat "mvn -B -DdevelopmentVersion=${params.developmentVersion} -DreleaseVersion=${params.releaseVersion} -Dresume=false release:prepare release:perform"
}
stage('publish docs') {
bat "yarn docs --silent --name \"@blueriq/material - ${params.releaseVersion}\""
bat "build-publish-docs.bat ${params.releaseVersion} ${params.communityHost} ${params.communityUser} ${params.communityPass}"
}
} // end if
} catch (anyException) {
echo "An error occured (${anyException}) marking build as failed."
currentBuild.result = 'FAILURE'
} finally {
stage("Publish results") {
// Test results
step([$class: 'JUnitResultArchiver', testResults: 'testresults/*.xml'])
// coverage results
step([$class : 'hudson.plugins.cobertura.CoberturaPublisher',
coberturaReportFile : 'coverage/cobertura-coverage.xml',
onlyStable : false,
failUnhealthy : true,
failUnstable : true,
autoUpdateHealth : false,
autoUpdateStability : false,
zoomCoverageChart : false,
failNoReports : true,
// healthy, unhealthy, failing
lineCoverageTargets : '80.0, 80.0, 80.0',
packageCoverageTargets : '80.0, 80.0, 80.0',
fileCoverageTargets : '80.0, 80.0, 80.0',
classCoverageTargets : '80.0, 80.0, 80.0',
methodCoverageTargets : '80.0, 80.0, 80.0',
conditionalCoverageTargets: '80.0, 80.0, 80.0'
])
// lint results
step([$class : 'hudson.plugins.checkstyle.CheckStylePublisher',
pattern : '*_results_checkstyle.xml',
useStableBuildAsReference: true,
unstableTotalAll : '1',
shouldDetectModules : true,
canRunOnFailed : true])
}
if (isMaster && currentBuild.result.equals('SUCCESS')) {
stage('push to Github') {
withCredentials([usernamePassword(credentialsId: 'blueriq-material_github.com', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
// We want the tags now that where not fetched in the 'checkout' stage
bat "git fetch --tags"
bat "git remote add upstream \"https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/blueriq/blueriq-material.git\" "
// Push only the master branch and all tags to Github
bat "git push upstream master"
bat "git push upstream --tags"
}
}
}
notifyBuildStatus()
deleteDir()
}
}// node
def notifyBuildStatus() {
// notify the person who started the build and the persons who's commits broke the build
step([$class : 'Mailer',
notifyEveryUnstableBuild: true,
recipients : emailextrecipients([
[$class: 'CulpritsRecipientProvider'],
[$class: 'RequesterRecipientProvider']
])
])
step([$class : 'Mailer',
notifyEveryUnstableBuild: true,
sendToIndividuals : true
])
}