-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
161 lines (142 loc) · 5.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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!groovy
@Library('cib-pipeline-library') _
import de.cib.pipeline.library.Constants
import de.cib.pipeline.library.kubernetes.BuildPodCreator
import de.cib.pipeline.library.logging.Logger
import de.cib.pipeline.library.ConstantsInternal
import de.cib.pipeline.library.MavenProjectInformation
import groovy.transform.Field
@Field Logger log = new Logger(this)
@Field MavenProjectInformation mavenProjectInformation = null
@Field List<String> helmChartPaths = []
@Field Map pipelineParams = [
pom: ConstantsInternal.DEFAULT_MAVEN_POM_PATH,
mvnContainerName: Constants.MAVEN_JDK_17_CONTAINER,
uiParamPresets: [:],
testMode: false
]
pipeline {
agent {
kubernetes {
yaml BuildPodCreator.cibStandardPod()
.withContainerFromName(pipelineParams.mvnContainerName)
.withHelm3Container()
.withKanikoContainer()
.withSyftContainer()
.asYaml()
defaultContainer pipelineParams.mvnContainerName
}
}
// Parameter that can be changed in the Jenkins UI
parameters {
booleanParam(
name: 'DEPLOY',
defaultValue: false,
description: 'Deploy release artifacts to artifacts.cibseven.org'
)
}
options {
buildDiscarder(
logRotator(
// number of build logs to keep
numToKeepStr:'5',
// history to keep in days
daysToKeepStr: '15',
// artifacts are kept for days
artifactDaysToKeepStr: '15',
// number of builds have their artifacts kept
artifactNumToKeepStr: '5'
)
)
// Stop build after 120 minutes
timeout(time: 120, unit: 'MINUTES')
disableConcurrentBuilds()
}
stages {
stage('Print Settings & Checkout') {
steps {
script {
printSettings()
def pom = readMavenPom file: pipelineParams.pom
// for overlays often no groupId is set as the parent groupId is used
def groupId = pom.groupId
if (groupId == null) {
groupId = pom.parent.groupId
log.info "parent groupId is used"
}
mavenProjectInformation = new MavenProjectInformation(groupId, pom.artifactId, pom.version, pom.name, pom.description)
log.info "Build Project: ${mavenProjectInformation.groupId}:${mavenProjectInformation.artifactId}, ${mavenProjectInformation.name} with version ${mavenProjectInformation.version}"
// Avoid Git "dubious ownership" error in checked out repository. Needed in
// build containers with newer Git versions. Originates from Jenkins running
// pipeline as root but repository being owned by user 1000. For more, see
// https://stackoverflow.com/questions/72978485/git-submodule-update-failed-with-fatal-detected-dubious-ownership-in-repositor
sh "git config --global --add safe.directory \$(pwd)"
}
}
}
stage('Build and Deploy') {
steps {
script {
withMaven(options: [artifactsPublisher(archiveFilesDisabled: false)]) {
def COMMAND = "package"
if (params.DEPLOY == true) {
COMMAND = "deploy"
}
sh """
mvn -DskipTests \
org.cyclonedx:cyclonedx-maven-plugin:makeAggregateBom \
${COMMAND} \
-Dnexus.release.repository.id=mvn-cibseven-public \
-Dnexus.release.repository=https://artifacts.cibseven.org/repository/public
"""
}
}
}
}
}
post {
always {
script {
log.info 'End of the build'
}
}
success {
script {
log.info '✅ Build successful'
if (params.RELEASE_BUILD == true) {
notifyResult(
office365WebhookId: pipelineParams.office365WebhookId,
message: "Application was successfully released with version ${mavenProjectInformation.version}"
)
}
}
}
unstable {
script {
log.warning '⚠️ Build unstable'
}
}
failure {
script {
log.warning '❌ Build failed'
if (env.BRANCH_NAME == 'master') {
notifyResult(
office365WebhookId: pipelineParams.office365WebhookId,
message: "Access build info at ${env.BUILD_URL}"
)
}
}
}
fixed {
script {
log.info '✅ Previous issues fixed'
if (env.BRANCH_NAME == 'master') {
notifyResult(
office365WebhookId: pipelineParams.office365WebhookId,
message: "Access build info at ${env.BUILD_URL}"
)
}
}
}
}
}