forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildInfoYaml.groovy
69 lines (66 loc) · 2.49 KB
/
buildInfoYaml.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
/*
* 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.
*/
def call(Map args = [:]) {
try {
unstash "buildInfo_yml"
} catch(Exception ex) {
echo("No buildInfo.yml exists in stashed. Starting initialize the buildInfo yaml file.")
}
def inputManifest = args.inputManifest ?: "buildInfo.yml"
def sourceyml = readYaml(file: inputManifest)
def outputyml = args.outputyml ?: "buildInfo.yml"
def components = args.componentName
def componentsList = []
def status = args.status
echo("The status is $status")
echo("Components is $components")
if (!components.isEmpty()) {
echo ("Components parameter is not null")
for (component in components.split(" ")) {
componentsList.add(component.trim())
}
} else {
echo ("Components parameter is null")
sourceyml.components.each { component ->
componentsList.add(component.name)
}
}
echo (componentsList.toString())
if (args.stage == "INITIALIZE_STAGE") {
echo("Initiate the build info yaml file.")
sourceyml.build.status = "IN_PROGRESS"
sourceyml.build.number = "${BUILD_NUMBER}"
sourceyml.results = [:]
sourceyml.results.startTimestamp = currentBuild.startTimeInMillis
} else if (args.stage == "FINALIZE_STAGE") {
sourceyml.components.each { component ->
if (componentsList.contains(component.name)) {
// Convert ref from branch to commit
dir(component.name) {
checkout([$class: 'GitSCM', branches: [[name: component.ref]],
userRemoteConfigs: [[url: component.repository]]])
def commitID = sh(
script: "git rev-parse HEAD",
returnStdout: true
).trim()
component.ref = commitID
}
}
}
sourceyml.build.status = status
sourceyml.results.duration = currentBuild.duration
} else {
stageField = args.stage
echo("stage is $stageField")
echo("status is $status")
sourceyml.results.("$stageField".toString()) = status
}
writeYaml(file: outputyml, data: sourceyml, overwrite: true)
sh ("cat $outputyml")
stash includes: "buildInfo.yml", name: "buildInfo_yml"
}