forked from opendevstack/ods-document-generation-svc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
72 lines (64 loc) · 2.12 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
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: [
'*' : 'dev',
"${odsGitRef}" : 'test'
],
debug: true
) { context ->
stageBuild(context)
odsComponentStageScanWithSonar(context, [branch: '*'])
odsComponentStageBuildOpenShiftImage(context)
stageCreatedImageTagLatest(context)
}
def stageBuild(def context) {
def javaOpts = "-Xmx512m"
def gradleTestOpts = "-Xmx128m"
stage('Build and Unit Test') {
withEnv(["TAGVERSION=${context.tagversion}", "NEXUS_HOST=${context.nexusHost}", "NEXUS_USERNAME=${context.nexusUsername}", "NEXUS_PASSWORD=${context.nexusPassword}", "JAVA_OPTS=${javaOpts}", "GRADLE_TEST_OPTS=${gradleTestOpts}"]) {
// get wkhtml
sh (
script : """
curl -kLO https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
tar vxf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
mv wkhtmltox/bin/wkhtmlto* /usr/bin
""",
label : "get and install wkhtml"
)
def status = sh(
script: "./gradlew clean test shadowJar --stacktrace --no-daemon",
label : "gradle build",
returnStatus: true
)
if (status != 0) {
error "Build failed!"
}
status = sh(
script: "cp build/libs/*-all.jar ./docker/app.jar",
label : "copy resources into docker context",
returnStatus: true
)
if (status != 0) {
error "Copying failed!"
}
}
}
}
def stageCreatedImageTagLatest(def context) {
stage('Tag created image') {
def targetImageTag = context.gitBranch.replace('/','_').replace('-','_')
sh(
script: "oc -n ${context.targetProject} tag ${context.componentId}:${context.shortGitCommit} ${context.componentId}:${targetImageTag}",
label: "Set tag '${targetImageTag}' on is/${context.componentId}"
)
}
}