This repository has been archived by the owner on Jan 2, 2019. It is now read-only.
/
archiveArtifacts.groovy
59 lines (51 loc) · 1.88 KB
/
archiveArtifacts.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
/*
* archiveArtifacts- override the built-in `archiveArtifacts` step.
*/
def call(Map args) {
assert args.artifacts
if (args.artifacts =~ /\*/) {
error "archiveArtifacts with external storage doesn't support patterns right now"
}
String propertyName = 'hudson.model.DirectoryBrowserSupport.CSP'
/* Mess with Jenkins' Content-Security Policy settings to allow our
* redirects, gnarly
*/
if (null == System.getProperty(propertyName)) {
System.setProperty(propertyName,
'sandbox allow-scripts allow-same-origin;')
}
String uploadScriptName = '__azure-upload.sh'
/* Only grab the file if it doesn't exist already */
if (!fileExists(uploadScriptName)) {
String uploadScript = libraryResource 'io/codevalet/externalartifacts/upload-file-azure.sh'
writeFile file: uploadScriptName, text: uploadScript
}
String uploadedUrl
withCredentials([string(credentialsId: 'azure-access-key',
variable: 'AZURE_ACCESS_KEY')]) {
uploadedUrl = sh(script: "bash ${uploadScriptName} ${args.artifacts}",
returnStdout: true).trim()
}
if (uploadedUrl =~ 'https://') {
/* if the output was a URL, generate our redirect file */
String redirectFile = "${args.artifacts}.html"
String redirectHtml = """<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="0;URL=${uploadedUrl}" />
<title>Redirecting...</title>
</head>
<body>
<center>${args.artifacts} can be downloaded <a href="${uploadedUrl}">from Azure</a></center>
</body>
</html>"""
writeFile file: redirectFile, text:redirectHtml
steps.archiveArtifacts redirectFile
}
else {
echo uploadedUrl
}
}
def call(String artifacts) {
return call(artifacts: artifacts)
}