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

OZG-6923 update imageTag/helmVersion in jenkinsfile

parent 36981c24
No related branches found
No related tags found
No related merge requests found
......@@ -90,7 +90,7 @@ pipeline {
script {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
dir('alfa-client') {
IMAGE_TAG = generateImageTag()
IMAGE_TAG = buildVersionName()
withNPM(npmrcConfig: 'npm-nexus-auth') {
sh 'npm run ci-build-alfa-client-container'
......@@ -133,7 +133,7 @@ pipeline {
steps {
script {
FAILED_STAGE=env.STAGE_NAME
IMAGE_TAG = generateImageTag()
IMAGE_TAG = buildVersionName()
configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) {
sh 'mvn --version'
......@@ -198,7 +198,7 @@ pipeline {
steps {
script {
FAILED_STAGE=env.STAGE_NAME
HELM_CHART_VERSION = generateHelmChartVersion()
HELM_CHART_VERSION = buildVersionName()
sh "./run_helm_test.sh"
......@@ -217,7 +217,7 @@ pipeline {
script {
dir('alfa-client') {
FAILED_STAGE=env.STAGE_NAME
HELM_CHART_VERSION = generateHelmChartVersion()
HELM_CHART_VERSION = buildVersionName()
sh "./run_helm_test.sh"
......@@ -268,7 +268,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')]) {
......@@ -329,20 +329,27 @@ Void deployHelmChart(String helmChartVersion, String app ) {
}
}
String generateHelmChartVersion() {
def chartVersion = "${VERSION}"
if (isMasterBranch()) {
chartVersion += getCommitHash()
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 (isBarrierefreiheitBranch()) {
chartVersion += "-barrierefreiheit${getCommitHash()}"
return branchName
}
String buildVersionName() {
if (isReleaseBranch()) {
return getRootPomVersion(pomFile)
}
else if (!isReleaseBranch()) {
chartVersion += "-${env.BRANCH_NAME}"
if (isBarrierefreiheitBranch()) {
return "${getRootPomVersion(pomFile)}-barrierefreiheit${getCommitHash()}".replaceAll("_", "-")
}
return chartVersion.replaceAll("_", "-")
return "${getRootPomVersion(pomFile)}-${validateBranchName(env.BRANCH_NAME)}-${env.GIT_COMMIT.take(7)}".replaceAll("_", "-")
}
Void tagAndPushDockerImage(String newTag){
......@@ -354,16 +361,6 @@ Void tagAndPushDockerImage(String newTag){
}
}
String generateImageTag() {
def imageTag = "${env.BRANCH_NAME}-${VERSION}"
if (isMasterBranch() || isBarrierefreiheitBranch()) {
imageTag += getCommitHash()
}
return imageTag
}
Void cloneGitopsRepo() {
withCredentials([usernamePassword(credentialsId: 'jenkins-gitea-access-token', passwordVariable: 'TOKEN', usernameVariable: 'USER')]) {
sh 'git clone https://${USER}:${TOKEN}@git.ozg-sh.de/ozgcloud-devops/gitops.git'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment