This repository has been archived by the owner on Sep 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
JenkinsfileTrigger
118 lines (110 loc) · 5.97 KB
/
JenkinsfileTrigger
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
env.PAAS_SLAVE = "paas-sig-ci-slave01"
properties(
[
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '25', daysToKeepStr: '', numToKeepStr: '50')),
disableConcurrentBuilds(),
pipelineTriggers([cron('H */3 * * *')]),
]
)
node (env.PAAS_SLAVE) {
def currentStage = ""
ansiColor('xterm') {
timestamps {
//deleteDir()
try {
currentStage = 'PaaS-CI-CD-Trigger'
stage(currentStage) {
if( fileExists("versions.log.groovy") ) {
load('versions.log.groovy')
sh '''
CURRENT_ORIGIN_VERSION=$( git ls-remote --tags https://github.com/openshift/origin | sort -t '/' -k 3 -V | tail -1 | awk '{print $2}' | sed 's/refs\\/tags\\/\\(.*\\)/\\1/' | sed 's/\\^{}//' )
CURRENT_OA_VERSION=$( git ls-remote --tags https://github.com/openshift/openshift-ansible | egrep 'openshift-ansible-[0-9]' | sort -t '/' -k 3 -V | tail -1 | awk '{print $2}' | sed 's/refs\\/tags\\/\\(.*\\)/\\1/' | sed 's/\\^{}//' )
if [ "${CURRENT_ORIGIN_VERSION}" != "${ORIGIN_VERSION}" ]; then
touch BUILD_ORIGIN
fi
if [ "${CURRENT_OA_VERSION}" != "${OA_VERSION}" ]; then
touch BUILD_OA
fi
'''
} else {
touch BUILD_ORIGIN
touch BUILD_OA
}
sh '''
echo "ORIGIN_VERSION=$( git ls-remote --tags https://github.com/openshift/origin | sort -t '/' -k 3 -V | tail -1 | awk '{print $2}' | sed 's/refs\\/tags\\/\\(.*\\)/\\1/' | sed 's/\\^{}//' )" > versions.log
echo "OA_VERSION=$( git ls-remote --tags https://github.com/openshift/openshift-ansible | egrep 'openshift-ansible-[0-9]' | sort -t '/' -k 3 -V | tail -1 | awk '{print $2}' | sed 's/refs\\/tags\\/\\(.*\\)/\\1/' | sed 's/\\^{}//' )" >> versions.log
'''
convertProps('versions.log')
load('versions.log.groovy')
}
} catch (e) {
// Set build result
currentBuild.result = 'FAILURE'
// Report the exception
echo "Error: Exception from " + currentStage + ":"
echo e.getMessage()
// Throw the error
throw e
} finally {
echo "Gathered origin and openshift-ansible versions!"
if( fileExists("BUILD_ORIGIN") && (! fileExists("BUILD_OA") ) ) {
echo "BUILD ORIGIN PROJECT ONLY! "
build job: 'paas-ci-cd',
parameters: [
string(name: 'ORIGIN_VERSION', value: "${env.ORIGIN_VERSION}"),
string(name: 'OA', value: "${env.OA_VERSION}"),
booleanParam(name: 'SCRATCH', value: false),
booleanParam(name: 'BE', value: false),
booleanParam(name: 'BUILD_ORIGIN', value: true),
booleanParam(name: 'BUILD_OA', value: false)
],
wait: true
sh "rm -f BUILD_ORIGIN"
}
if( fileExists("BUILD_OA") && (! fileExists("BUILD_ORIGIN") ) ) {
echo "BUILD OA PROJECT ONLY!"
build job: 'paas-ci-cd',
parameters: [
string(name: 'ORIGIN_VERSION', value: "${env.ORIGIN_VERSION}"),
string(name: 'OA', value: "${env.OA_VERSION}"),
booleanParam(name: 'SCRATCH', value: false),
booleanParam(name: 'BE', value: false),
booleanParam(name: 'BUILD_ORIGIN', value: false),
booleanParam(name: 'BUILD_OA', value: true)
],
wait: true
sh "rm -f BUILD_OA"
}
if( fileExists("BUILD_OA") && fileExists("BUILD_ORIGIN") ) {
echo "BUILD ORIGIN AND BUILD OA PROJECTS"
build job: 'paas-ci-cd',
parameters: [
string(name: 'ORIGIN_VERSION', value: "${env.ORIGIN_VERSION}"),
string(name: 'OA', value: "${env.OA_VERSION}"),
booleanParam(name: 'SCRATCH', value: false),
booleanParam(name: 'BE', value: false),
booleanParam(name: 'BUILD_ORIGIN', value: true),
booleanParam(name: 'BUILD_OA', value: true)
],
wait: true
sh "rm -f BUILD_ORIGIN"
sh "rm -f BUILD_OA"
}
currentBuild.displayName = "origin-${env.ORIGIN_VERSION} - ${env.OA_VERSION}"
currentBuild.description = ''
currentBuild.description = currentBuild.description + "origin-${env.ORIGIN_VERSION} :: "
currentBuild.description += "${env.OA_VERSION}"
step([$class: 'ArtifactArchiver', allowEmptyArchive: true, artifacts: '*.log, *.groovy', fingerprint: true])
}
}
}
}
/**
* Convert bash shell properties to groovy
* shellFile - Pass a shell formatted properties file
*/
def convertProps(shellFile) {
def command = $/awk -F'=' '{print "env."$1"=\""$2"\""}' ${shellFile} > ${shellFile}.groovy/$
sh command
return "${shellFile}.groovy"
}