Skip to content
Snippets Groups Projects
Commit d5b6d1b5 authored by Bastian Heppener's avatar Bastian Heppener
Browse files

Merge branch 'OZG-6923' into 'main'

OZG-6923 add commitId to feature branch image tag/helm version

See merge request !3
parents 92c43ec2 f8b3ec45
Branches
Tags
1 merge request!3OZG-6923 add commitId to feature branch image tag/helm version
......@@ -107,7 +107,7 @@ pipeline {
steps {
script {
FAILED_STAGE=env.STAGE_NAME
IMAGE_TAG_BAYERN_ID_PROXY = generateImageTag('pom.xml')
IMAGE_TAG_BAYERN_ID_PROXY = buildVersionName('pom.xml')
tagAndPushDockerImage('bayernid-proxy', IMAGE_TAG_BAYERN_ID_PROXY)
......@@ -127,7 +127,7 @@ pipeline {
script {
FAILED_STAGE=env.STAGE_NAME
HELM_CHART_VERSION_BAYERN_ID_PROXY = generateHelmChartVersion("pom.xml")
HELM_CHART_VERSION_BAYERN_ID_PROXY = buildVersionName("pom.xml")
sh "./run_helm_test.sh"
......@@ -178,7 +178,7 @@ pipeline {
stage ('Deploy SBOM to DependencyTrack') {
steps {
script {
IMAGE_TAG = generateImageTag('pom.xml')
IMAGE_TAG = buildVersionName('pom.xml')
configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) {
withCredentials([string(credentialsId: 'dependency-track-api-key', variable: 'API_KEY')]) {
......@@ -253,17 +253,22 @@ void deployHelmChart(String helmChartName, String helmChartVersion) {
}
}
String generateHelmChartVersion(String pomFile) {
def chartVersion = getPomVersion(pomFile)
if (env.BRANCH_NAME == 'main') {
chartVersion += "-${env.GIT_COMMIT.take(7)}"
}
else if (env.BRANCH_NAME != 'release') {
chartVersion += "-${env.BRANCH_NAME}"
String validateBranchName(branchName) {
int maxLength = 19
if (branchName.length() > maxLength) {
String originalBranchName = branchName
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 chartVersion.replaceAll("_", "-")
String buildVersionName(String pomFile) {
if (isReleaseBranch()) {
return getPomVersion(pomFile)
}
return "${getPomVersion(pomFile)}-${validateBranchName(env.BRANCH_NAME)}-${env.GIT_COMMIT.take(7)}".replaceAll("_", "-")
}
Void tagAndPushDockerImage(String imageName, String newTag){
......@@ -281,16 +286,6 @@ String getPomVersion(String pomFile){
return pom.version
}
String generateImageTag(String pomFile) {
def imageTag = "${env.BRANCH_NAME}-${getPomVersion(pomFile)}"
if (env.BRANCH_NAME == 'main') {
imageTag += "-${env.GIT_COMMIT.take(7)}"
}
return imageTag
}
String generateBranchPRJarTag(String pomFile) {
def jarTag = getPomVersion(pomFile).replace("SNAPSHOT", "${env.BRANCH_NAME}-SNAPSHOT")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment