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

Merge pull request 'OZG-6923 add commitId to feature branch image tag/helm...

Merge pull request 'OZG-6923 add commitId to feature branch image tag/helm version' (#59) from OZG-6923 into master

Reviewed-on: https://git.ozg-sh.de/ozgcloud-app/administration/pulls/59


Reviewed-by: default avatarOZGCloud <ozgcloud@mgm-tp.com>
parents cdea76cc cf089c2c
Branches
Tags
No related merge requests found
...@@ -10,8 +10,8 @@ pipeline { ...@@ -10,8 +10,8 @@ pipeline {
SNAPSHOT_REGEX = /\d+.\d+.\d+-SNAPSHOT/ SNAPSHOT_REGEX = /\d+.\d+.\d+-SNAPSHOT/
FAILED_STAGE = "" FAILED_STAGE = ""
SH_SUCCESS_STATUS_CODE = 0 SH_SUCCESS_STATUS_CODE = 0
IMAGE_TAG = generateImageTag() IMAGE_TAG = buildVersionName()
HELM_CHART_VERSION = generateHelmChartVersion() HELM_CHART_VERSION = buildVersionName()
BUILD_PROFILE = getBuildProfile() BUILD_PROFILE = getBuildProfile()
} }
...@@ -109,7 +109,7 @@ pipeline { ...@@ -109,7 +109,7 @@ pipeline {
stage ('Deploy SBOM to DependencyTrack') { stage ('Deploy SBOM to DependencyTrack') {
steps { steps {
script { script {
IMAGE_TAG = generateImageTag() IMAGE_TAG = buildVersionName()
configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) { configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) {
withCredentials([string(credentialsId: 'dependency-track-api-key', variable: 'API_KEY')]) { withCredentials([string(credentialsId: 'dependency-track-api-key', variable: 'API_KEY')]) {
...@@ -141,7 +141,7 @@ pipeline { ...@@ -141,7 +141,7 @@ pipeline {
steps { steps {
script { script {
FAILED_STAGE=env.STAGE_NAME FAILED_STAGE=env.STAGE_NAME
HELM_CHART_VERSION = generateHelmChartVersion() HELM_CHART_VERSION = buildVersionName()
dir('src/main/helm') { dir('src/main/helm') {
sh "helm lint -f ../../test/helm-linter-values.yaml" sh "helm lint -f ../../test/helm-linter-values.yaml"
...@@ -224,8 +224,22 @@ String getHelmRepository(){ ...@@ -224,8 +224,22 @@ String getHelmRepository(){
return 'ozg-base-apps-snapshot'; return 'ozg-base-apps-snapshot';
} }
String generateImageTag() { String validateBranchName(branchName) {
return "${env.BRANCH_NAME}-${getPomVersion()}" 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() { String getPomVersion() {
...@@ -347,16 +361,3 @@ Boolean isMasterBranch() { ...@@ -347,16 +361,3 @@ Boolean isMasterBranch() {
Boolean isReleaseBranch() { Boolean isReleaseBranch() {
return env.BRANCH_NAME == 'release' 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