-
Notifications
You must be signed in to change notification settings - Fork 30
/
Jenkinsfile
129 lines (122 loc) · 5.01 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
118
119
120
121
122
123
124
125
126
127
128
129
def artifact_glob="deployments/launcher/target/*.tar.gz"
def artifact="deployments/launcher/target/*-skinny.tar.gz"
def data_artifact="deployments/launcher/target/*-data.tar.gz"
def ocp_map = '/mnt/ocp/jenkins-openshift-mappings.json'
def bc_section = 'build-configs'
def my_bc = null
pipeline {
agent { label 'maven-jdk11' }
stages {
stage('Prepare') {
steps {
sh 'printenv'
}
}
stage('Build & Functional Test') {
when {
expression { env.CHANGE_ID != null } // Pull request
}
steps {
withEnv(['JAVA_HOME=/usr/lib/jvm/java-11-openjdk', 'JAVA_11_HOME=/usr/lib/jvm/java-11-openjdk', 'SKIP_NPM_CONFIG=false']){
sh 'mvn -B -V clean verify -Prun-its -Pci --global-toolchains toolchains.xml'
}
}
}
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') {
when {
allOf {
expression { my_bc != null }
expression { env.CHANGE_ID == null } // Not pull request
}
}
steps {
withEnv(['JAVA_HOME=/usr/lib/jvm/java-11-openjdk']){
sh 'mvn -B -V clean install -DskipNpmConfig=false --global-toolchains toolchains.xml'
}
}
}
stage('Deploy') {
when {
allOf {
expression { my_bc != null }
expression { env.CHANGE_ID == null } // Not pull request
}
}
steps {
echo "Deploy"
withEnv(['JAVA_HOME=/usr/lib/jvm/java-11-openjdk', 'JAVA_11_HOME=/usr/lib/jvm/java-11-openjdk']){
sh 'mvn help:effective-settings -B -V -DskipTests=true -DskipNpmConfig=false deploy -e --global-toolchains toolchains.xml'
}
}
}
stage('Archive') {
steps {
echo "Archive"
archiveArtifacts artifacts: "$artifact_glob", fingerprint: true
}
}
stage('Build & Push Image') {
when {
allOf {
expression { my_bc != null }
expression { env.CHANGE_ID == null } // Not pull request
}
}
steps {
script {
def artifact_file = sh(script: "ls $artifact", returnStdout: true)?.trim()
def tarball_url = "${BUILD_URL}artifact/$artifact_file"
openshift.withCluster() {
openshift.withProject() {
echo "Starting image build: ${openshift.project()}:${my_bc}"
def bc = openshift.selector("bc", my_bc)
def data_artifact_file = sh(script: "ls $data_artifact", returnStdout: true)?.trim()
def data_tarball_url = "${BUILD_URL}artifact/$data_artifact_file"
def buildSel = bc.startBuild("-e tarball_url=${tarball_url} -e data_tarball_url=${data_tarball_url}")
buildSel.logs("-f")
}
}
}
}
}
}
}