-
Notifications
You must be signed in to change notification settings - Fork 19
/
Jenkinsfile
77 lines (69 loc) · 2.66 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
/* generated jenkins file used for building and deploying @component_id@ in projects @project_id@ */
def final projectId = '@project_id@'
def final componentId = '@component_id@'
def final credentialsId = "${projectId}-cd-cd-user-with-password"
def sharedLibraryRepository
def dockerRegistry
node {
sharedLibraryRepository = env.SHARED_LIBRARY_REPOSITORY
dockerRegistry = env.DOCKER_REGISTRY
}
library identifier: 'ods-library@production', retriever: modernSCM(
[$class: 'GitSCMSource',
remote: sharedLibraryRepository,
credentialsId: credentialsId])
/*
See readme of shared library for usage and customization
@ https://github.com/opendevstack/ods-jenkins-shared-library/blob/master/README.md
eg. to create and set your own builder slave instead of
the maven/gradle slave used here - the code of the slave can be found at
https://github.com/opendevstack/ods-project-quickstarters/tree/master/jenkins-slaves/maven
*/
odsPipeline(
image: "${dockerRegistry}/cd/jenkins-slave-maven",
projectId: projectId,
componentId: componentId,
branchToEnvironmentMapping: [
'master': 'test',
'*': 'dev'
]
) { context ->
stageBuild(context)
stageScanForSonarqube(context)
//Enable following line if you want to upload your artifact to nexus
//stageUploadToNexus(context)
stageStartOpenshiftBuild(context)
stageDeployToOpenshift(context)
}
def stageBuild(def context) {
def javaOpts = "-Xmx512m"
def gradleTestOpts = "-Xmx128m"
def springBootEnv = context.environment
if (springBootEnv.contains('-dev')) {
springBootEnv = 'dev'
}
stage('Build') {
withEnv(["TAGVERSION=${context.tagversion}", "NEXUS_HOST=${context.nexusHost}", "NEXUS_USERNAME=${context.nexusUsername}", "NEXUS_PASSWORD=${context.nexusPassword}", "JAVA_OPTS=${javaOpts}","GRADLE_TEST_OPTS=${gradleTestOpts}","ENVIRONMENT=${springBootEnv}"]) {
def status = sh(script: "./gradlew clean build --stacktrace --no-daemon", returnStatus: true)
junit 'build/test-results/test/*.xml'
if (status != 0) {
error "Build failed!"
}
}
}
}
def stageUploadToNexus(def context) {
def javaOpts = "-Xmx512m"
def springBootEnv = context.environment
if (springBootEnv.contains('-dev')) {
springBootEnv = 'dev'
}
stage('UploadArtifact') {
withEnv(["TAGVERSION=${context.tagversion}", "NEXUS_HOST=${context.nexusHost}", "NEXUS_USERNAME=${context.nexusUsername}", "NEXUS_PASSWORD=${context.nexusPassword}", "JAVA_OPTS=${javaOpts}","ENVIRONMENT=${springBootEnv}"]) {
def deployStatus = sh(script: "./gradlew publish --stacktrace --no-daemon", returnStatus: true)
if (deployStatus != 0) {
error "Deployment to nexus failed!"
}
}
}
}