-
Notifications
You must be signed in to change notification settings - Fork 4
/
Jenkinsfile
97 lines (94 loc) · 3.47 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
def artifact="target/*.jar"
def artifact_runner="target/*-runner.jar"
def ocp_map = '/mnt/ocp/jenkins-openshift-mappings.json'
def bc_section = 'build-configs'
def my_bc = null
pipeline {
agent { label 'maven-36-jdk11' }
stages {
stage('Prepare') {
steps {
sh 'printenv'
}
}
stage('Build & ITs') {
when {
expression { env.CHANGE_ID != null } // Pull request
}
steps {
sh '${M2_HOME}/bin/mvn -B -V clean verify sonar:sonar -Prun-its'
}
}
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}"
}
}
}
}
stage('Deploy') {
when { branch 'master' }
steps {
echo "Deploy"
sh '${M2_HOME}/bin/mvn help:effective-settings -B -V clean deploy -e'
}
}
stage('Archive') {
steps {
echo "Archive"
archiveArtifacts artifacts: "$artifact", fingerprint: true
}
}
stage('Build & Push Image') {
when {
allOf {
expression { my_bc != null }
expression { env.CHANGE_ID == null } // Not pull request
}
}
steps {
script {
def artifact_runner_file = sh(script: "ls $artifact_runner", returnStdout: true)?.trim()
def tarball_url = "${BUILD_URL}artifact/$artifact_runner_file"
openshift.withCluster() {
openshift.withProject() {
echo "Starting image build: ${openshift.project()}:${my_bc}"
def bc = openshift.selector("bc", my_bc)
def buildSel = bc.startBuild("-e tarball_url=${tarball_url}")
buildSel.logs("-f")
}
}
}
}
}
}
}