Skip to content
Snippets Groups Projects
Commit 9c5534fb authored by Martin's avatar Martin
Browse files

OZG-7922 adjust image tag generation

parent b3b0dc73
Branches
No related tags found
1 merge request!2Ozg 7922 fix keycloak operator exception
...@@ -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 = generateHelmChartVersion() HELM_CHART_VERSION = generateImageTag();
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 = generateHelmChartVersion() HELM_CHART_VERSION = generateImageTag()
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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment