Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
document-manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OZG-Cloud
app
document-manager
Commits
b4fda5f7
Commit
b4fda5f7
authored
8 months ago
by
OZGCloud
Browse files
Options
Downloads
Patches
Plain Diff
OZG-6811 Add Jeninsfile
parent
64b8231f
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Jenkinsfile
+162
-0
162 additions, 0 deletions
Jenkinsfile
with
162 additions
and
0 deletions
Jenkinsfile
0 → 100644
+
162
−
0
View file @
b4fda5f7
pipeline
{
agent
{
node
{
label
'ozgcloud-jenkins-build-agent-jdk21'
}
}
environment
{
BLUE_OCEAN_URL
=
"https://jenkins.infra.ozg-cloud.systems/job/ozgcloud-document-manager/job/${env.BRANCH_NAME}/${env.BUILD_NUMBER}/"
RELEASE_REGEX
=
/\d+.\d+.\d+/
SNAPSHOT_REGEX
=
/\d+.\d+.\d+-SNAPSHOT/
FAILED_STAGE
=
""
SH_SUCCESS_STATUS_CODE
=
0
}
options
{
timeout
(
time:
1
,
unit:
'HOURS'
)
disableConcurrentBuilds
()
buildDiscarder
(
logRotator
(
numToKeepStr:
'5'
))
}
stages
{
stage
(
'Check Version'
)
{
steps
{
script
{
FAILED_STAGE
=
env
.
STAGE_NAME
def
rootVersion
=
getPomVersion
(
'pom.xml'
)
def
serverVersion
=
getParentPomVersion
(
'document-manager-server/pom.xml'
)
def
interfaceVersion
=
getPomVersion
(
'document-manager-interface/pom.xml'
)
if
(
serverVersion
!=
rootVersion
){
error
(
"document-manager-server Version stimmt nicht mit root überein"
)
}
if
(
interfaceVersion
!=
rootVersion
){
error
(
"document-manager-interface Version stimmt nicht mit root überein"
)
}
if
(
env
.
BRANCH_NAME
==
'release'
){
if
(
!(
rootVersion
==~
RELEASE_REGEX
))
{
error
(
"Keine Release Version für Branch ${env.BRANCH_NAME}."
)
}
}
else
{
if
(
!(
rootVersion
==~
SNAPSHOT_REGEX
))
{
error
(
"Keine Snapshot Version für Branch ${env.BRANCH_NAME}."
)
}
}
}
}
}
stage
(
'Set Version'
)
{
when
{
not
{
anyOf
{
branch
'master'
branch
'release'
}
}
}
steps
{
script
{
FAILED_STAGE
=
env
.
STAGE_NAME
JAR_TAG
=
getPomVersion
(
'pom.xml'
).
replace
(
"SNAPSHOT"
,
"${env.BRANCH_NAME}-SNAPSHOT"
)
}
configFileProvider
([
configFile
(
fileId:
'maven-settings'
,
variable:
'MAVEN_SETTINGS'
)])
{
sh
"mvn --no-transfer-progress -s $MAVEN_SETTINGS versions:set -DnewVersion=${JAR_TAG} -DprocessAllModules=true"
}
}
}
stage
(
'Build Document-Manager'
)
{
steps
{
script
{
FAILED_STAGE
=
env
.
STAGE_NAME
}
configFileProvider
([
configFile
(
fileId:
'maven-settings'
,
variable:
'MAVEN_SETTINGS'
)])
{
sh
'mvn --no-transfer-progress -s $MAVEN_SETTINGS clean install -Dmaven.wagon.http.retryHandler.count=3'
}
}
}
stage
(
'Deploy to Nexus'
){
steps
{
script
{
FAILED_STAGE
=
env
.
STAGE_NAME
}
configFileProvider
([
configFile
(
fileId:
'maven-settings'
,
variable:
'MAVEN_SETTINGS'
)])
{
sh
'mvn --no-transfer-progress -s $MAVEN_SETTINGS -DskipTests deploy -Dmaven.wagon.http.retryHandler.count=3'
}
}
}
stage
(
'Sonar Checks'
)
{
when
{
branch
'master'
}
steps
{
script
{
FAILED_STAGE
=
env
.
STAGE_NAME
configFileProvider
([
configFile
(
fileId:
'maven-settings'
,
variable:
'MAVEN_SETTINGS'
)])
{
try
{
withSonarQubeEnv
(
'sonarqube-ozg-sh'
){
sh
'mvn -s $MAVEN_SETTINGS sonar:sonar'
}
}
catch
(
Exception
e
)
{
unstable
(
"SonarQube failed"
)
}
}
}
}
}
}
post
{
always
{
junit
testResults:
'**/target/surefire-reports/*.xml'
,
skipPublishingChecks:
true
}
failure
{
script
{
if
(
env
.
BRANCH_NAME
==
'master'
||
env
.
BRANCH_NAME
==
'release'
)
{
sendFailureMessage
()
}
}
}
}
}
Void
sendFailureMessage
()
{
def
room
=
''
def
data
=
"""{"msgtype":"m.text",
"body":"Document-Manager: Build Failed. Stage: ${FAILED_STAGE} Build-ID: ${env.BUILD_NUMBER} Link: ${BLUE_OCEAN_URL}",
"format": "org.matrix.custom.html",
"formatted_body":"<h3>Document-Manager: Build Failed.</h3><b>Stage:</b> ${FAILED_STAGE}<br><b>Build-ID:</b> <a href='${BLUE_OCEAN_URL}'>${env.BUILD_NUMBER}</a>"}"""
if
(
env
.
BRANCH_NAME
==
'master'
)
{
room
=
"!GjqhmouBtnDbwUkAjx:matrix.ozg-sh.de"
}
else
if
(
env
.
BRANCH_NAME
==
'release'
)
{
room
=
"!oWZpUGTFsxkJIYNfYg:matrix.ozg-sh.de"
}
sh
"curl -XPOST -H 'authorization: Bearer ${getElementAccessToken()}' -d '${data}' https://matrix.ozg-sh.de/_matrix/client/v3/rooms/$room/send/m.room.message"
}
String
getElementAccessToken
()
{
withCredentials
([
string
(
credentialsId:
'element-login-json'
,
variable:
'LOGIN_JSON'
)])
{
return
readJSON
(
text:
sh
(
script:
'''curl -XPOST -d \"$LOGIN_JSON\" https://matrix.ozg-sh.de/_matrix/client/v3/login'''
,
returnStdout:
true
)).
access_token
}
}
String
getPomVersion
(
String
pomFile
){
def
pom
=
readMavenPom
file:
pomFile
return
pom
.
version
}
String
getParentPomVersion
(
String
filePath
)
{
def
pom
=
readMavenPom
file:
filePath
return
pom
.
parent
.
version
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment