Skip to content
Snippets Groups Projects
Commit b5f5c1dd authored by OZGCloud's avatar OZGCloud
Browse files

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

parent fe5db804
Branches
No related tags found
No related merge requests found
......@@ -134,7 +134,7 @@ pipeline {
steps {
script {
FAILED_STAGE=env.STAGE_NAME
IMAGE_TAG = generateImageTag()
IMAGE_TAG = buildVersionName()
tagAndPushDockerImage(IMAGE_TAG)
......@@ -153,7 +153,7 @@ pipeline {
steps {
script {
FAILED_STAGE=env.STAGE_NAME
HELM_CHART_VERSION = generateHelmChartVersion()
HELM_CHART_VERSION = buildVersionName()
dir('info-manager-server') {
sh "./run_helm_test.sh"
......@@ -205,7 +205,7 @@ pipeline {
stage ('Deploy SBOM to DependencyTrack') {
steps {
script {
IMAGE_TAG = generateImageTag()
IMAGE_TAG = buildVersionName()
configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) {
withCredentials([string(credentialsId: 'dependency-track-api-key', variable: 'API_KEY')]) {
......@@ -259,17 +259,22 @@ Void loginToDockerRepo() {
}
String generateHelmChartVersion() {
def chartVersion = getPomVersion('pom.xml')
if (env.BRANCH_NAME == 'master') {
chartVersion += "-${env.GIT_COMMIT.take(7)}"
def validateBranchName(branchName) {
int maxLength = 30
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."
}
else if (env.BRANCH_NAME != 'release') {
chartVersion += "-${env.BRANCH_NAME}"
return branchName
}
return chartVersion.replaceAll("_", "-")
String buildVersionName() {
if (env.BRANCH_NAME == 'release') {
return getPomVersion('pom.xml')
}
return "${getPomVersion('pom.xml')}-${validateBranchName(env.BRANCH_NAME)}-${env.GIT_COMMIT.take(7)}".replaceAll("_", "-")
}
Void tagAndPushDockerImage(String newTag){
......@@ -287,16 +292,6 @@ String getPomVersion(String pomFile){
return pom.version
}
String generateImageTag() {
def imageTag = "${env.BRANCH_NAME}-${getPomVersion('pom.xml')}"
if (env.BRANCH_NAME == 'master') {
imageTag += "-${env.GIT_COMMIT.take(7)}"
}
return imageTag
}
Void configureGit() {
final email = "jenkins@ozg-sh.de"
final name = "jenkins"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment