This repository has been archived by the owner on Mar 8, 2021. It is now read-only.
forked from pngowda/xtext-build-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compositeRepositories.groovy
49 lines (42 loc) · 1.83 KB
/
compositeRepositories.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
import jenkins.model.*
import hudson.model.*
import groovy.xml.XmlUtil
def addChildToComposite (String compositeDescriptorPath, String childLocation) {
XmlUtil xmlUtil = new XmlUtil()
def xmlFromFile = new File(compositeDescriptorPath)
def repository = new XmlSlurper( false, false ).parseText(xmlFromFile.getText())
xmlUtil.serialize(repository, new FileWriter(new File(compositeDescriptorPath+".bak")))
repository.properties.property[0].value = System.currentTimeMillis()
if (!repository.children.child.any { node -> node.@location == childLocation }) {
repository.children.appendNode {
child (location:childLocation)
}
println "${compositeDescriptorPath}: child ${childLocation} added"
} else {
println "${compositeDescriptorPath}: child ${childLocation} already exists"
}
xmlUtil.serialize(repository, new FileWriter(xmlFromFile))
}
def getBuildId (String promotePropertiesPath) {
Properties props = new Properties()
File propsFile = new File(promotePropertiesPath)
props.load(propsFile.newDataInputStream())
return props.getProperty('build.id')
}
def getVersion (String publisherPropertiesPath) {
Properties props = new Properties()
File propsFile = new File(publisherPropertiesPath)
props.load(propsFile.newDataInputStream())
return props.getProperty('version')
}
def buildType = System.getProperty('BUILD_TYPE')
def buildId = getBuildId('build-result/promote.properties')
def version = getVersion('build-result/publisher.properties')
if (buildType == 'S') {
addChildToComposite('build-result/composite/compositeArtifacts.xml', buildId)
addChildToComposite('build-result/composite/compositeContent.xml', buildId)
}
if (buildType == 'R') {
addChildToComposite('build-result/composite/compositeArtifacts.xml', version)
addChildToComposite('build-result/composite/compositeContent.xml', version)
}