forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getManifestSHA.groovy
48 lines (42 loc) · 1.68 KB
/
getManifestSHA.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
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
Map call(Map args = [:]) {
String inputManifest = args.inputManifest ?: "manifests/${INPUT_MANIFEST}"
String jobName = args.jobName ?: "${JOB_NAME}"
buildManifest(
args + [
inputManifest: inputManifest,
lock: true
]
)
String manifestLock = "${inputManifest}.lock"
String manifestSHA = sha1(manifestLock)
echo "Manifest SHA: ${manifestSHA}"
def lib = library(identifier: 'jenkins@20211123', retriever: legacySCM(scm))
def inputManifestObj = lib.jenkins.InputManifest.new(readYaml(file: manifestLock))
String shasRoot = inputManifestObj.getSHAsRoot(jobName)
String manifestSHAPath = "${shasRoot}/${manifestSHA}.yml"
echo "Manifest lock: ${manifestLock}"
echo "Manifest SHA path: ${manifestSHAPath}"
Boolean manifestSHAExists = false
withCredentials([string(credentialsId: 'jenkins-aws-account-public', variable: 'AWS_ACCOUNT_PUBLIC'),
string(credentialsId: 'jenkins-artifact-bucket-name', variable: 'ARTIFACT_BUCKET_NAME')]) {
withAWS(role: 'opensearch-bundle', roleAccount: "${AWS_ACCOUNT_PUBLIC}", duration: 900, roleSessionName: 'jenkins-session') {
if (s3DoesObjectExist(bucket: "${ARTIFACT_BUCKET_NAME}", path: manifestSHAPath)) {
manifestSHAExists = true
}
}
}
echo "Manifest SHA exists: ${manifestSHAExists}"
return [
sha: manifestSHA,
lock: manifestLock,
path: manifestSHAPath,
exists: manifestSHAExists
]
}