-
-
Notifications
You must be signed in to change notification settings - Fork 138
/
Copy pathpublishReports.groovy
64 lines (58 loc) · 2.56 KB
/
publishReports.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
#!/usr/bin/env groovy
/**
* Wrapper for publishing reports to the reports host
*
* See https://issues.jenkins-ci.org/browse/INFRA-947 for more
*/
def call(List<String> files, Map params = [:]) {
def timeout = params.get('timeout') ?: '60'
if (!infra.isTrusted() && !infra.isInfra()) {
error 'Can only call publishReports from within the trusted.ci environment'
}
withCredentials([string(credentialsId: 'azure-reports-access-key', variable: 'AZURE_STORAGE_KEY'),]) {
// Sanity Check to check that `az` is installed, in the PATH, and in a decent version
sh 'az version'
for(int i = 0; i < files.size(); ++i) {
String filename = files[i]
withEnv(['HOME=/tmp']) {
String uploadFlags = ''
switch (filename) {
case ~/(?i).*\.html/:
uploadFlags = '--content-type="text/html"'
break
case ~/(?i).*\.css/:
uploadFlags = '--content-type="text/css"'
break
case ~/(?i).*\.json/:
uploadFlags = '--content-type="application/json"'
break
case ~/(?i).*\.js/:
uploadFlags = '--content-type="application/javascript"'
break
case ~/(?i).*\.gif/:
uploadFlags = '--content-type="image/gif"'
break
case ~/(?i).*\.png/:
uploadFlags = '--content-type="image/png"'
break
}
def directory = filename.split("/")
def basename = directory[directory.size() - 1]
def dirname = Arrays.copyOfRange(directory, 0, directory.size()-1 ).join("/")
withEnv([
"TIMEOUT=${timeout}",
"FILENAME=${filename}",
"UPLOADFLAGS=${uploadFlags}",
"SOURCE_DIRNAME=${dirname ?: '.'}",
"DESTINATION_PATH=${dirname ?: '/'}",
"PATTERN=${ basename ?: '*' }",
]) {
// Blob container can be removed once files are uploaded on the azure file storage
sh 'az storage blob upload --account-name=prodjenkinsreports --container=reports --timeout=${TIMEOUT} --file=${FILENAME} --name=${FILENAME} ${UPLOADFLAGS} --overwrite'
// `az storage file upload` doesn't support file uploaded in a remote directory that doesn't exist but upload-batch yes. Unfortunately the cli syntax is a bit different and requires filename and directory name to be set differently.
sh 'az storage file upload-batch --account-name prodjenkinsreports --destination reports --source ${SOURCE_DIRNAME} --destination-path ${DESTINATION_PATH} --pattern ${PATTERN} ${UPLOADFLAGS}'
}
}
}
}
}