-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease-pipeline.groovy
198 lines (175 loc) · 6.29 KB
/
release-pipeline.groovy
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
187
188
189
190
191
192
193
194
195
196
197
198
/*
Jenkins Release pipeline
Required non-default plugins:
1. HTTP Request
2. Pipeline Utility Steps
3. Build Name and Description Setter
Required parameters list:
1. NODE
2. DISTRIB_VERSION
3. CREATE_RELEASE
4. XRAY_VERSION
5. REPO_CLONE_URL
6. REPO_BRANCH
7. XRAY_DOWNLOADS_URL
8. CREATE_RELEASE_URL
9. UPLOAD_ASSETS_URL
10.AUTH_TOKEN
*/
node(params.NODE) {
cleanWs()
stage("Checks") {
requiredParametersNames = [
"NODE", "DISTRIB_VERSION", "XRAY_VERSION",
"REPO_CLONE_URL", "REPO_BRANCH", "XRAY_DOWNLOADS_URL",
"CREATE_RELEASE_URL", "UPLOAD_ASSETS_URL", "AUTH_TOKEN"
]
undefinedParams = []
requiredParametersNames.each { paramName ->
if (params[paramName] == null || params[paramName] == "") {
undefinedParams << paramName
}
}
if (undefinedParams) {
error("Required params are undefined: $undefinedParams")
}
}
buildName "#$BUILD_NUMBER $DISTRIB_VERSION"
repoDir = "${pwd()}/veepeenet"
venvPath = "${pwd()}/venv"
xrayDistribPath = "${pwd()}/Xray-linux-64"
distribName = "veepeenet-$DISTRIB_VERSION"
distribPath = "${pwd()}/$distribName"
archiveDistribName = "veepeenet.tar.gz"
archiveDistribPath = "${pwd()}/$archiveDistribName"
metaFilePath = "${pwd()}/meta.json"
stage("Sources") {
dir(repoDir) {
log "Cloning $params.REPO_CLONE_URL, branch: $params.REPO_BRANCH"
git url: params.REPO_CLONE_URL, branch: params.REPO_BRANCH
log "Repository cloned"
}
}
stage("Prepare") {
dir(repoDir) {
log "Creating python virtual environment"
sh "python3 -m venv $venvPath"
log "Virtual environment created"
log "Install python dependencies"
sh "$venvPath/bin/pip install --upgrade pip"
sh "$venvPath/bin/pip install mockito pylint"
log "Dependencies installed"
}
}
stage("Linting") {
log "Start code linting"
dir(repoDir) {
try {
results = []
for (module in findFiles(glob: "*.py")) {
results << sh(script: "$venvPath/bin/pylint $module.name", returnStatus: true)
}
if (results.any {code -> code != 0 }) {
error("Code styling need works")
}
log "Linting success"
} catch (Exception ex) {
unstable(ex.getMessage())
log ex.getMessage()
}
}
}
stage("Tests") {
withEnv(["PYTHONPATH=$repoDir"]) {
dir("$repoDir/test") {
try {
log "Run tests"
sh "$venvPath/bin/python -m unittest discover -v -p '*_test.py'"
log "Tests success"
} catch (Exception ex) {
message = "Tests failed"
println ex.getMessage()
unstable message
log message
}
}
}
}
stage("Xray") {
outputFileName = "Xray-linux-64.zip"
log "Download Xray distrib"
httpRequest url: "$XRAY_DOWNLOADS_URL/$XRAY_VERSION/Xray-linux-64.zip", outputFile: outputFileName
log "Xray distrib downloaded"
log "Unpack Xray distrib"
unzip zipFile: outputFileName, dir: xrayDistribPath
log "Xray distrib unpacked"
}
stage("Distrib") {
log "Generating meta file"
meta = [
version: DISTRIB_VERSION,
buildNumber: BUILD_NUMBER,
buildDate: new Date().toString()
]
writeJSON file: metaFilePath, json: meta
log "Meta file generated"
log "Building distrib"
dir(distribPath) {
log "Copy required components"
[
"$repoDir/install.sh", "$repoDir/install-wg.sh", "$repoDir/install-xray.sh",
"$repoDir/uninstall.sh", "$repoDir/uninstall-wg.sh", "$repoDir/uninstall-xray.sh",
"$repoDir/*.py", "$repoDir/xray.service", metaFilePath
].each { component ->
sh "cp $component ./"
}
sh "chmod 755 *.sh"
sh "cp -r $xrayDistribPath ./"
log "Required components successfully copied"
}
log "Archiving distrib"
tar file: archiveDistribPath, archive: true, compress: true, glob: "$distribName/**"
archiveArtifacts artifacts: archiveDistribName
log "Archive created"
}
if (params.CREATE_RELEASE) {
stage("Release") {
withCredentials([string(credentialsId: AUTH_TOKEN, variable: "github_token")]) {
log "Creating release draft"
releaseResponse = httpRequest url: CREATE_RELEASE_URL, contentType: "APPLICATION_JSON_UTF8", httpMode: 'POST',
customHeaders: [
[name: "Authorization", value: "Bearer $github_token"],
],
requestBody: writeJSON(
json: [
tag_name: DISTRIB_VERSION,
target_commitish: REPO_BRANCH,
name: "VeePeeNET $DISTRIB_VERSION",
draft: true,
prerelease: false,
generate_release_notes: false
],
returnText: true
)
releaseId = readJSON(text: releaseResponse.content)["id"]
log "Release draft created (id: $releaseId)"
log "Uploading archive distrib to release draft"
httpRequest url: "$UPLOAD_ASSETS_URL/$releaseId/assets?name=$archiveDistribName", httpMode: 'POST',
contentType: "APPLICATION_OCTETSTREAM",
customHeaders: [
[name: "Authorization", value: "Bearer $github_token"],
],
uploadFile: archiveDistribPath,
wrapAsMultipart: false
log "Archive distrib uploaded"
}
}
} else {
log "Skip release creation"
}
}
def log(message) {
timestamps {
echo "$message"
}
}