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 {
script {
FAILED_STAGE=env.STAGE_NAME
IMAGE_TAG = generateImageTag('pom.xml')
IMAGE_TAG = buildVersionName('pom.xml')
tagAndPushDockerImage('vorgang-manager', IMAGE_TAG)
......@@ -134,7 +134,7 @@ pipeline {
steps {
script {
FAILED_STAGE=env.STAGE_NAME
HELM_CHART_VERSION = generateHelmChartVersion("pom.xml")
HELM_CHART_VERSION = buildVersionName("pom.xml")
sh "./run_helm_test.sh"
......@@ -184,7 +184,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')]) {
......@@ -269,17 +269,22 @@ void deployHelmChart(String helmChartName, String helmChartVersion) {
}
}
String generateHelmChartVersion(String pomFile) {
def chartVersion = getPomVersion(pomFile)
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(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){
......@@ -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() {
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