This repository has been archived by the owner on Mar 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathJenkinsfile
117 lines (105 loc) · 3.46 KB
/
Jenkinsfile
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
#!/usr/bin/groovy
@Library('github.com/fabric8io/fabric8-pipeline-library@master')
def utils = new io.fabric8.Utils()
def initServiceGitHash
def releaseVersion
// wait until the slower ci centos build has finished, then we know the image is in the devtools registry
node {
checkout scm
if (utils.isCD()){
waitForCentosCIJob()
}
}
goTemplate{
dockerNode{
ws {
checkout scm
if (utils.isCI()){
goCI{
githubOrganisation = 'fabric8-services'
dockerOrganisation = 'fabric8'
project = 'fabric8-tenant'
dockerBuildOptions = '--file Dockerfile.deploy'
makeTarget = 'build test-unit-no-coverage-junit'
}
sh('mv /home/jenkins/go/src/github.com/fabric8-services/fabric8-tenant/tmp/junit.xml `pwd`')
junit 'junit.xml'
} else if (utils.isCD()){
releaseVersion = goRelease{
githubOrganisation = 'fabric8-services'
dockerOrganisation = 'fabric8'
project = 'fabric8-tenant'
dockerBuildOptions = '--file Dockerfile.deploy'
}
initServiceGitHash = sh(script: 'git rev-parse HEAD', returnStdout: true).toString().trim()
pushPomPropertyChangePR{
propertyName = 'init-tenant.version'
projects = [
'fabric8io/fabric8-platform'
]
version = releaseVersion
containerName = 'go'
}
}
}
if (utils.isCD()){
ws{
container(name: 'go') {
def flow = new io.fabric8.Fabric8Commands()
flow.setupGitSSH()
def uid = UUID.randomUUID().toString()
def branch = "versionUpdate${uid}"
def message = "Update tenants version to ${releaseVersion}"
sh """
git clone [email protected]:openshiftio/saas-openshiftio --depth 1
cd saas-openshiftio
git checkout -b ${branch}
sed -i -r 's/- hash: .*/- hash: ${initServiceGitHash}/g' dsaas-services/f8-tenant.yaml
git commit -a -m ${message}
git push origin ${branch}
"""
def prId = flow.createPullRequest(message, gitRepo, branch)
flow.mergePR(gitRepo, prId)
}
}
}
}
}
def waitForCentosCIJob(){
retry(5){
// skip the merge commit and get the git sha for the actual change
def commit = sh(script: "git --no-pager log -1 --no-merges --pretty=format:\"%H\"", returnStdout: true).toString().trim()
echo "Check CI centos has finished it's build for commit ${commit}"
def jobListUrl = new URL("https://ci.centos.org/view/Devtools/job/devtools-fabric8-tenant-build-master/api/json?tree=builds[id,changeSet[items[commitId]]]")
def rs = restGetURL{
url = jobListUrl
}
def buildNumber
for (build in rs.builds){
if (build.changeSet){
for (item in build.changeSet.items){
if (commit == item.commitId){
echo "matched commit ${commit}"
buildNumber = build.id
break
}
}
}
if (buildNumber){
break
}
}
if (!buildNumber){
error "no CI centos build found yet for commit ${commit}"
sleep 60
}
waitUntil {
def buildUrl = new URL("https://ci.centos.org/view/Devtools/job/devtools-fabric8-tenant-build-master/${buildNumber}/api/json")
def build = restGetURL{
url = buildUrl
}
echo "CI centos build ${buildNumber} is ${build.result}"
build.result == 'SUCCESS'
}
}
}