Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
operator
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
devops
operator
Commits
9c5534fb
Commit
9c5534fb
authored
2 months ago
by
Martin
Browse files
Options
Downloads
Patches
Plain Diff
OZG-7922 adjust image tag generation
parent
b3b0dc73
Branches
Branches containing commit
No related tags found
1 merge request
!2
Ozg 7922 fix keycloak operator exception
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Jenkinsfile
+24
-24
24 additions, 24 deletions
Jenkinsfile
with
24 additions
and
24 deletions
Jenkinsfile
+
24
−
24
View file @
9c5534fb
...
@@ -80,7 +80,7 @@ pipeline {
...
@@ -80,7 +80,7 @@ pipeline {
steps
{
steps
{
script
{
script
{
FAILED_STAGE
=
env
.
STAGE_NAME
FAILED_STAGE
=
env
.
STAGE_NAME
JAR_TAG
=
getPomVersion
(
'pom.xml'
).
replace
(
"SNAPSHOT"
,
"${env.BRANCH_NAME}-SNAPSHOT"
)
JAR_TAG
=
getPomVersion
().
replace
(
"SNAPSHOT"
,
"${env.BRANCH_NAME}-SNAPSHOT"
)
}
}
configFileProvider
([
configFile
(
fileId:
'maven-settings'
,
variable:
'MAVEN_SETTINGS'
)])
{
configFileProvider
([
configFile
(
fileId:
'maven-settings'
,
variable:
'MAVEN_SETTINGS'
)])
{
sh
"mvn -s $MAVEN_SETTINGS versions:set -DnewVersion=${JAR_TAG} -DprocessAllModules=true"
sh
"mvn -s $MAVEN_SETTINGS versions:set -DnewVersion=${JAR_TAG} -DprocessAllModules=true"
...
@@ -166,7 +166,7 @@ pipeline {
...
@@ -166,7 +166,7 @@ pipeline {
steps
{
steps
{
script
{
script
{
FAILED_STAGE
=
env
.
STAGE_NAME
FAILED_STAGE
=
env
.
STAGE_NAME
HELM_CHART_VERSION
=
generate
HelmChartVersion
()
HELM_CHART_VERSION
=
generate
ImageTag
()
;
testAndDeployKeycloakHelmChart
(
HELM_CHART_VERSION
)
testAndDeployKeycloakHelmChart
(
HELM_CHART_VERSION
)
}
}
...
@@ -177,7 +177,7 @@ pipeline {
...
@@ -177,7 +177,7 @@ pipeline {
steps
{
steps
{
script
{
script
{
FAILED_STAGE
=
env
.
STAGE_NAME
FAILED_STAGE
=
env
.
STAGE_NAME
HELM_CHART_VERSION
=
generate
HelmChartVersion
()
HELM_CHART_VERSION
=
generate
ImageTag
()
testAndDeployElasticsearchHelmChart
(
HELM_CHART_VERSION
)
testAndDeployElasticsearchHelmChart
(
HELM_CHART_VERSION
)
}
}
...
@@ -259,19 +259,6 @@ String getHelmRepoUrl(){
...
@@ -259,19 +259,6 @@ String getHelmRepoUrl(){
return
"https://nexus.ozg-sh.de/service/rest/v1/components?repository=ozg-base-apps-snapshot"
return
"https://nexus.ozg-sh.de/service/rest/v1/components?repository=ozg-base-apps-snapshot"
}
}
String
generateHelmChartVersion
()
{
def
chartVersion
=
getPomVersion
(
'pom.xml'
)
if
(
isMainBranch
())
{
chartVersion
+=
"-${env.GIT_COMMIT.take(7)}"
}
else
if
(!
isReleaseBranch
())
{
chartVersion
+=
"-${env.BRANCH_NAME}"
}
return
chartVersion
.
replaceAll
(
'_'
,
'-'
)
}
Boolean
isMainBranch
()
{
Boolean
isMainBranch
()
{
return
env
.
BRANCH_NAME
==
'main'
return
env
.
BRANCH_NAME
==
'main'
}
}
...
@@ -370,20 +357,33 @@ Void tagAndPushDockerImage(String imageName, String newTag){
...
@@ -370,20 +357,33 @@ Void tagAndPushDockerImage(String imageName, String newTag){
}
}
}
}
String
getPomVersion
(
String
pomFile
){
String
generateImageTag
()
{
def
pom
=
readMavenPom
file:
pomFile
if
(
isReleaseBranch
())
{
return
getPomVersion
()
}
return
"${getPomVersion()}-${validateBranchName(env.BRANCH_NAME)}${getCommitHash()}"
.
replaceAll
(
"_"
,
"-"
)
}
String
getPomVersion
(){
def
pom
=
readMavenPom
file:
'pom.xml'
return
pom
.
version
return
pom
.
version
}
}
String
generateImageTag
()
{
String
validateBranchName
(
branchName
)
{
def
imageTag
=
"${env.BRANCH_NAME}-${getPomVersion('pom.xml')}"
int
maxLength
=
20
if
(
branchName
.
length
()
>
maxLength
)
{
if
(
env
.
BRANCH_NAME
==
'main'
)
{
String
originalBranchName
=
branchName
imageTag
+=
"-${env.GIT_COMMIT.take(7)}"
branchName
=
branchName
.
substring
(
0
,
maxLength
)
echo
"WARNING: Branch name '${originalBranchName}' exceeded ${maxLength} characters. "
+
"It has been truncated to '${branchName}' for deployment purposes."
}
}
return
branchName
}
return
imageTag
String
getCommitHash
()
{
return
"-${env.GIT_COMMIT.take(7)}"
;
}
}
String
getParentPomVersion
(
String
filePath
)
{
String
getParentPomVersion
(
String
filePath
)
{
...
...
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