-
Notifications
You must be signed in to change notification settings - Fork 4
/
Jenkinsfile
149 lines (135 loc) · 4.14 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
#! groovy
library 'pipeline-library'
def nodeVersion = '10.17.0'
def npmVersion = 'latest' // We can change this without any changes to Jenkins. 5.7.1 is minimum to use 'npm ci'
def packageVersion = ''
def isPR = env.BRANCH_NAME.startsWith('PR-')
def runDanger = isPR
def MAINLINE_BRANCH_REGEXP = /master|next|\d_\d+_(X|\d)/ // a branch is considered mainline if 'master' or like 1_13_X
def isMainlineBranch = (env.BRANCH_NAME ==~ MAINLINE_BRANCH_REGEXP)
def isMaster = 'master'.equals(env.BRANCH_NAME)
def unitTests(titaniumBranch, nodeVersion, npmVersion) {
checkout scm
nodejs(nodeJSInstallationName: "node ${nodeVersion}") {
ansiColor('xterm') {
timeout(55) {
ensureNPM(npmVersion)
sh 'npm ci'
// Install titanium cli
ensureNPMPackageVersion('titanium')
// Install titanium SDK and select it
if ('GA'.equals(titaniumBranch)) {
sh 'ti sdk install latest -d'
} else if ('master'.equals(titaniumBranch)) {
sh 'ti sdk install -b master -d'
}
try {
withEnv(["PATH+ALLOY=${pwd()}/bin"]) {
sh 'npm test'
}
} finally {
junit 'TEST-*.xml'
stash includes: 'TEST-*.xml', name: "test-report-${titaniumBranch}"
}
} // timeout
} // ansi
} // nodejs
deleteDir()
}
timestamps() {
try {
node('(osx || linux) && git && !master') {
stage('Lint') {
checkout scm
packageVersion = jsonParse(readFile('package.json'))['version']
currentBuild.displayName = "#${packageVersion}-${currentBuild.number}"
fingerprint 'package.json'
nodejs(nodeJSInstallationName: "node ${nodeVersion}") {
ensureNPM(npmVersion)
// Install dependencies
timeout(5) {
sh 'npm ci'
}
sh 'npm run lint'
} // nodejs
stash includes: 'package.json,package-lock.json', name: 'security'
} // stage('Lint')
} // node
stage('Test') {
parallel(
'GA SDK': {
node('(osx || linux) && git && !master') {
unitTests('GA', nodeVersion, npmVersion)
}
},
'master SDK': {
node('(osx || linux) && git && !master') {
unitTests('master', nodeVersion, npmVersion)
}
}
)
}
node('(osx || linux) && git && !master') {
stage('Security') {
unstash 'security'
nodejs(nodeJSInstallationName: "node ${nodeVersion}") {
npmAuditToWarnings() // runs npm audit --json, converts to format needed by scanner and writes to npm-audit.json file
recordIssues blameDisabled: true, enabledForFailure: true, forensicsDisabled: true, tools: [issues(name: 'NPM Audit', pattern: 'npm-audit.json')]
} // nodejs
deleteDir()
} // stage
} // node
node('(osx || linux) && git && npm-publish && !master') {
stage('Publish') {
checkout scm
nodejs(nodeJSInstallationName: "node ${nodeVersion}") {
if (isMainlineBranch) {
try {
// Publish
sh 'npm publish'
// Tag git
pushGitTag(name: packageVersion, message: "See ${env.BUILD_URL} for more information.", force: true)
if (isMaster) {
// Trigger appc-cli job
build job: '../appc-cli/master', wait: false, parameters: [
[$class: 'StringParameterValue', name: 'packageName', value: 'alloy' ],
[$class: 'StringParameterValue', name: 'packageVersion', value: packageVersion ],
]
}
// Update tickets
updateJIRA('ALOY', "Alloy ${packageVersion}", scm)
} catch (e) {
// Don't thow the errors as we don't want a failed publish due to the version not being bumped
// being classed as a failure on the build
}
} // if
} // nodejs
deleteDir()
} // stage
} // node
} finally {
if (runDanger) {
stage('Danger') {
node('(osx || linux) && !master') {
nodejs(nodeJSInstallationName: "node ${nodeVersion}") {
checkout scm
try {
unstash 'test-report-master'
} catch (e) {}
try {
unstash 'test-report-GA'
} catch (e) {}
ensureNPM(npmVersion)
timeout(5) {
sh 'npm ci'
}
withEnv(["DANGER_JS_APP_INSTALL_ID=''"]) {
sh returnStatus: true, script: 'npx danger ci --verbose'
} // withEnv
} // nodejs
deleteDir()
} // node
} // stage
} // if
}
} // timestamps