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

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

parent 12e68915
Branches
Tags
No related merge requests found
......@@ -10,8 +10,8 @@ pipeline {
SNAPSHOT_REGEX = /\d+.\d+.\d+-SNAPSHOT/
FAILED_STAGE = ""
SH_SUCCESS_STATUS_CODE = 0
IMAGE_TAG = generateImageTag()
HELM_CHART_VERSION = generateHelmChartVersion()
IMAGE_TAG = buildVersionName()
HELM_CHART_VERSION = buildVersionName()
BUILD_PROFILE = getBuildProfile()
}
......@@ -109,7 +109,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')]) {
......@@ -141,7 +141,7 @@ pipeline {
steps {
script {
FAILED_STAGE=env.STAGE_NAME
HELM_CHART_VERSION = generateHelmChartVersion()
HELM_CHART_VERSION = buildVersionName()
dir('src/main/helm') {
sh "helm lint -f ../../test/helm-linter-values.yaml"
......@@ -224,8 +224,22 @@ String getHelmRepository(){
return 'ozg-base-apps-snapshot';
}
String generateImageTag() {
return "${env.BRANCH_NAME}-${getPomVersion()}"
String 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."
}
return branchName
}
String buildVersionName() {
if (isReleaseBranch()) {
return getPomVersion()
}
return "${getPomVersion()}-${validateBranchName(env.BRANCH_NAME)}-${env.GIT_COMMIT.take(7)}".replaceAll("_", "-")
}
String getPomVersion() {
......@@ -347,16 +361,3 @@ Boolean isMasterBranch() {
Boolean isReleaseBranch() {
return env.BRANCH_NAME == 'release'
}
String generateHelmChartVersion() {
def chartVersion = getPomVersion()
if (isMasterBranch()) {
chartVersion += "-${env.GIT_COMMIT.take(7)}"
}
else if (!isReleaseBranch()) {
chartVersion += "-${env.BRANCH_NAME}"
}
return chartVersion.replaceAll("_", "-").take(63 - "administration-".length())
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment