Skip to content
Snippets Groups Projects
Commit a123f160 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' (#505) from OZG-6923 into master

Reviewed-on: https://git.ozg-sh.de/ozgcloud-app/vorgang-manager/pulls/505


Reviewed-by: default avatarOZGCloud <ozgcloud@mgm-tp.com>
parents 3c3bb2fb 130bae9e
Branches
Tags
No related merge requests found
...@@ -115,7 +115,7 @@ pipeline { ...@@ -115,7 +115,7 @@ pipeline {
script { script {
FAILED_STAGE=env.STAGE_NAME FAILED_STAGE=env.STAGE_NAME
IMAGE_TAG = generateImageTag('pom.xml') IMAGE_TAG = buildVersionName('pom.xml')
tagAndPushDockerImage('vorgang-manager', IMAGE_TAG) tagAndPushDockerImage('vorgang-manager', IMAGE_TAG)
...@@ -134,7 +134,7 @@ pipeline { ...@@ -134,7 +134,7 @@ pipeline {
steps { steps {
script { script {
FAILED_STAGE=env.STAGE_NAME FAILED_STAGE=env.STAGE_NAME
HELM_CHART_VERSION = generateHelmChartVersion("pom.xml") HELM_CHART_VERSION = buildVersionName("pom.xml")
sh "./run_helm_test.sh" sh "./run_helm_test.sh"
...@@ -184,7 +184,7 @@ pipeline { ...@@ -184,7 +184,7 @@ pipeline {
stage ('Deploy SBOM to DependencyTrack') { stage ('Deploy SBOM to DependencyTrack') {
steps { steps {
script { script {
IMAGE_TAG = generateImageTag('pom.xml') IMAGE_TAG = buildVersionName('pom.xml')
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')]) {
...@@ -269,17 +269,22 @@ void deployHelmChart(String helmChartName, String helmChartVersion) { ...@@ -269,17 +269,22 @@ void deployHelmChart(String helmChartName, String helmChartVersion) {
} }
} }
String generateHelmChartVersion(String pomFile) { def validateBranchName(branchName) {
def chartVersion = getPomVersion(pomFile) int maxLength = 30
if (branchName.length() > maxLength) {
if (env.BRANCH_NAME == 'master') { String originalBranchName = branchName
chartVersion += "-${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."
} }
else if (env.BRANCH_NAME != 'release') { return branchName
chartVersion += "-${env.BRANCH_NAME}"
} }
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){ Void tagAndPushDockerImage(String imageName, String newTag){
...@@ -310,16 +315,6 @@ void updateDependencyVersions(String bescheidManagerSnapshotVersion, String vorg ...@@ -310,16 +315,6 @@ void updateDependencyVersions(String bescheidManagerSnapshotVersion, String vorg
} }
} }
String generateImageTag(String pomFile) {
def imageTag = "${env.BRANCH_NAME}-${getPomVersion(pomFile)}"
if (env.BRANCH_NAME == 'master') {
imageTag += "-${env.GIT_COMMIT.take(7)}"
}
return imageTag
}
Void configureGit() { Void configureGit() {
final email = "jenkins@ozg-sh.de" final email = "jenkins@ozg-sh.de"
final name = "jenkins" final name = "jenkins"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment