-
Notifications
You must be signed in to change notification settings - Fork 20
/
Jenkinsfile
66 lines (60 loc) · 2.19 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
def odsNamespace
def odsGitRef
def odsImageTag
node {
odsNamespace = env.ODS_NAMESPACE ?: 'ods'
odsImageTag = env.ODS_IMAGE_TAG ?: 'latest'
odsGitRef = env.ODS_GIT_REF ?: 'master'
}
library("ods-jenkins-shared-library@${odsGitRef}")
odsComponentPipeline(
imageStreamTag: "${odsNamespace}/jenkins-agent-maven:${odsImageTag}",
branchToEnvironmentMapping: [:]
) { context ->
stageBuild(context)
odsComponentStageScanWithSonar(context, [branch: '*'])
odsComponentStageBuildOpenShiftImage(context, [branch: '*'])
stageTagImageWithBranch(context)
}
def stageBuild(def context) {
def javaOpts = "-Xmx512m"
def gradleTestOpts = "-Xmx128m"
def springBootEnv = context.environment
if (springBootEnv.contains('-dev')) {
springBootEnv = 'dev'
}
stage('Build and Unit Test') {
withEnv(["TAGVERSION=${context.tagversion}", "NEXUS_USERNAME=${context.nexusUsername}", "NEXUS_PASSWORD=${context.nexusPassword}", "NEXUS_HOST=${context.nexusHost}", "JAVA_OPTS=${javaOpts}","GRADLE_TEST_OPTS=${gradleTestOpts}","ENVIRONMENT=${springBootEnv}"]) {
def status = sh(script: '''
source use-j11.sh || echo 'ERROR: We could NOT setup jdk 11.'
./gradlew --version || echo 'ERROR: Could NOT get gradle version.'
java -version || echo 'ERROR: Could NOT get java version.'
echo "JAVA_HOME: $JAVA_HOME" || echo "ERROR: JAVA_HOME has NOT been set."
retryNum=0
downloadResult=1
while [ 0 -ne $downloadResult ] && [ 5 -gt $retryNum ]; do
set -x
./gradlew -i dependencies
set +x
downloadResult=$?
let "retryNum=retryNum+1"
done
set -x
./gradlew -i clean build --full-stacktrace --no-daemon
set +x
''', returnStatus: true)
if (status != 0) {
error "Build failed!"
}
}
}
}
def stageTagImageWithBranch(def context) {
stage('Tag created image') {
def targetImageTag = context.gitBranch.replace('/','_').replace('-','_')
sh(
script: "oc -n ${context.cdProject} tag ${context.componentId}:${context.shortGitCommit} ${context.componentId}:${targetImageTag}",
label: "Set tag '${targetImageTag}' on is/${context.componentId}"
)
}
}