forked from sinequa/sba-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.jenkinsfile
157 lines (136 loc) · 4.98 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
// ### Environment ###
properties([
parameters([
string(name:"SBA_VERSION", defaultValue: "", description: "Version of sba", trim: true),
string(name:"SBA_APP_LIST", defaultValue: "sba/sba-sinequa-analytics-internal", description: "App list to rebuild (comma separated)", trim: true),
string(name:"SBA_NODE", defaultValue: "${env.SBA_NODE}", description: "Execution node name", trim: true)
]),
disableConcurrentBuilds()
])
// Get mail parameters from jenkins env vars
url = "${env.NPM_SERVER_URL}"
npm_user = "${env.NPM_USER}"
npm_pass = "${env.NPM_PASS}"
npm_mail = "${env.NPM_MAIL}"
mailto = "${env.NPM_MAILING_LIST}"
// get job variables from job parameters
sba_version = "${params.SBA_VERSION}"
sba_app_list = "${params.SBA_APP_LIST}"
pkg_suffix = "-DEV"
sba_tag = ""
tag_prefix = "rel_"
// .npmrc variables for verdaccio connection
scope = "@sinequa"
fnpmrc = '.npmrc'
anpmrc = ["always-auth=true", "registry=${url}/", "scope=${scope}"]
// run job on a specific node if needed
node (params.SBA_NODE) {
currentBuild.result = "SUCCESS"
try {
// get the source code
checkout scm
// load jenkins functions
def rootDir = pwd()
def jf = load "${rootDir}/.jenkins_function.groovy"
stage('Clean') {
// delete dependency modules
def nmfolder = "node_modules"
echo ".Rmdir /s /q ${nmfolder}"
bat "if exist ${nmfolder} ( rmdir /s /q ${nmfolder} )"
// clean the npm cache
echo ".Cache clean force"
bat "npm cache clean --force"
}
stage('Create user') {
// create user for verdaccio
bat "npm-cli-login -u ${npm_user} -p ${npm_pass} -e ${npm_mail} -r ${url} -s ${scope} --config-path ${fnpmrc}"
// add connection infos in .npmrc file
jf.appendFile(fnpmrc, anpmrc)
// check the connection
bat "npm whoami"
}
stage('copyNpmrc') {
// copy .npmrc file in sub project folder
bat "xcopy ${fnpmrc} .\\projects\\core\\ /Y"
bat "xcopy ${fnpmrc} .\\projects\\components\\ /Y"
bat "xcopy ${fnpmrc} .\\projects\\analytics\\ /Y"
}
stage('NPM Install') {
// get the dependency modules
bat "npm i"
}
// check if we are in standard case of build or merge/validation (case of PR)
def action = jf.buildOrMerge()
if ("${action}" == "build") {
// validate the build in a PR after a commit
// build sinequa core modules
stage('Build Core') {
echo "npm run buildcore --if-present"
bat "npm run buildcore --if-present"
}
stage('Build Components') {
echo "npm run buildcomponents --if-present"
bat "npm run buildcomponents --if-present"
}
stage('Build Analytics') {
echo "npm run buildanalytics --if-present"
bat "npm run buildanalytics --if-present"
}
stage('Test Components') {
echo "npm run test components -- --watch=false"
bat "npm run test components -- --watch=false"
}
stage('Build HelloSearch') {
echo "npm run buildhellosearch --if-present"
bat "npm run buildhellosearch --if-present"
}
stage('Build Vanilla') {
echo "npm run buildvanilla --if-present"
bat "npm run buildvanilla --if-present"
}
stage('Build Pepper') {
echo "npm run buildpepper --if-present"
bat "npm run buildpepper --if-present"
}
} else {
// sba_version : releaseversion-DEV-build_number
sba_version = jf.get_pkg_version()
echo "sba_version: ${sba_version}"
sba_tag = jf.get_pkg_tag(sba_version)
echo "sba_tag: ${sba_tag}"
// validate the build before merge
// build sinequa core modules
stage('Build Core') {
echo "npm run buildsqcore --sq_version=${sba_version} --sq_tag=${sba_tag} --if-present"
bat "npm run buildsqcore --sq_version=${sba_version} --sq_tag=${sba_tag} --if-present"
}
stage('Build Components') {
echo "npm run buildsqcomponents --sq_version=${sba_version} --sq_tag=${sba_tag} --if-present"
bat "npm run buildsqcomponents --sq_version=${sba_version} --sq_tag=${sba_tag} --if-present"
}
stage('Build Analytics') {
echo "npm run buildsqanalytics --sq_version=${sba_version} --sq_tag=${sba_tag} --if-present"
bat "npm run buildsqanalytics --sq_version=${sba_version} --sq_tag=${sba_tag} --if-present"
}
// get the current branch version
def currentBranch = jf.findBranchNumber()
// When merging, build a list of apps (param of the job) to be validated
// Start a job with the name in the list in parameter
// The job must exists before run
echo "Build apps ${sba_app_list}"
def applist = sba_app_list.split(',')
// echo "applist: ${applist}"
def nbapp = applist.size()
def j = 0
for (int i=0; i < nbapp ; i++) {
j = i + 1
// call the app job with the params: version and branch
echo " app ${j}/${nbapp}: ${applist[i]}"
jf.build_app(sba_version, applist[i], currentBranch)
}
}
} catch (err) {
currentBuild.result = "FAILURE"
throw err
}
}