forked from Commonjava/indy-perf-tester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
85 lines (78 loc) · 3.33 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
def ocp_map = '/mnt/ocp/jenkins-openshift-mappings.json'
def bc_section = 'build-configs'
def my_bc = null
pipeline {
agent { label 'python' }
stages {
stage('Load OCP Mappings') {
when {
allOf {
expression { env.CHANGE_ID == null } // Not pull request
}
}
steps {
echo "Load OCP Mapping document"
script {
def exists = fileExists ocp_map
if (exists){
def jsonObj = readJSON file: ocp_map
if (bc_section in jsonObj){
if (env.GIT_URL in jsonObj[bc_section]) {
echo "Found BC for Git repo: ${env.GIT_URL}"
if (env.BRANCH_NAME in jsonObj[bc_section][env.GIT_URL]) {
my_bc = jsonObj[bc_section][env.GIT_URL][env.BRANCH_NAME]
} else {
my_bc = jsonObj[bc_section][env.GIT_URL]['default']
}
echo "Using BuildConfig: ${my_bc}"
}
else {
echo "Git URL: ${env.GIT_URL} not found in BC mapping."
}
}
else {
"BC mapping is invalid! No ${bc_section} sub-object found!"
}
}
else {
echo "JSON configuration file not found: ${ocp_map}"
}
if ( my_bc == null ) {
error("No valid BuildConfig reference found for Git URL: ${env.GIT_URL} with branch: ${env.BRANCH_NAME}")
}
}
}
}
stage('Build Image') {
when {
allOf {
expression { my_bc != null }
expression { env.CHANGE_ID == null } // Not pull request
}
}
steps {
script {
openshift.withCluster() {
openshift.withProject() {
echo "Starting image build: ${openshift.project()}:${my_bc}"
def bc = openshift.selector("bc", my_bc)
def buildSel = bc.startBuild()
echo "Started image build: ${buildSel.object().name}. Watching logs."
buildSel.logs("-f")
echo "Checking for image build result"
def buildStatus = buildSel.object().status.phase;
if ( buildStatus != "Complete") {
error( "Image build failed with status: ${buildStatus}")
}
// timeout(5) { // Throw exception after 20 minutes
// buildSel.untilEach(1) {
// return (it.object().status.phase == "Complete")
// }
// }
}
}
}
}
}
}
}