forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createSha512Checksums.groovy
32 lines (28 loc) · 1.39 KB
/
createSha512Checksums.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
Closure call() {
allowedFileTypes = [".tar.gz", ".zip", ".rpm"]
return { argsMap -> body: {
final foundFiles = sh(script: "find $argsMap.artifactPath -type f", returnStdout: true).split()
for (file in foundFiles) {
acceptTypeFound = false
for (fileType in allowedFileTypes) {
if (file.endsWith(fileType)) {
echo("Creating sha for ${file}")
final sha512 = sh(script: "sha512sum ${file}", returnStdout: true).split()
//sha512 is an array [shasum, filename]
final basename = sh(script: "basename ${sha512[1]}", returnStdout: true)
// writing to file accroding to opensearch requirement - "512shaHash<space><space>basename"
writeFile file: "${file}.sha512", text: "${sha512[0]} ${basename}"
acceptTypeFound = true
break
}
}
if (!acceptTypeFound) {
if(foundFiles.length == 1){
echo("Not generating sha for ${file} with artifact Path ${argsMap.artifactPath}, doesn't match allowed types ${allowedFileTypes}")
} else {
echo("Not generating sha for ${file} in ${argsMap.artifactPath}, doesn't match allowed types ${allowedFileTypes}")
}
}
}
}}
}