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

Merge pull request 'OZG-6923 update imageTag/helmVersion in jenkinsfile'...

Merge pull request 'OZG-6923 update imageTag/helmVersion in jenkinsfile' (#837) from OZG-6923 into master

Reviewed-on: https://git.ozg-sh.de/ozgcloud-app/alfa/pulls/837
parents ffb56d49 0232a3b1
No related branches found
No related tags found
No related merge requests found
...@@ -116,7 +116,7 @@ pipeline { ...@@ -116,7 +116,7 @@ pipeline {
script { script {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') { catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
dir('alfa-client') { dir('alfa-client') {
IMAGE_TAG = generateImageTag() IMAGE_TAG = buildVersionName()
withNPM(npmrcConfig: 'npm-nexus-auth') { withNPM(npmrcConfig: 'npm-nexus-auth') {
sh 'npm run ci-build-alfa-client-container' sh 'npm run ci-build-alfa-client-container'
...@@ -159,7 +159,7 @@ pipeline { ...@@ -159,7 +159,7 @@ pipeline {
steps { steps {
script { script {
FAILED_STAGE=env.STAGE_NAME FAILED_STAGE=env.STAGE_NAME
IMAGE_TAG = generateImageTag() IMAGE_TAG = buildVersionName()
configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) { configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) {
sh 'mvn --version' sh 'mvn --version'
...@@ -225,7 +225,7 @@ pipeline { ...@@ -225,7 +225,7 @@ pipeline {
steps { steps {
script { script {
FAILED_STAGE=env.STAGE_NAME FAILED_STAGE=env.STAGE_NAME
HELM_CHART_VERSION = generateHelmChartVersion() HELM_CHART_VERSION = buildVersionName()
sh "./run_helm_test.sh" sh "./run_helm_test.sh"
...@@ -242,9 +242,9 @@ pipeline { ...@@ -242,9 +242,9 @@ pipeline {
stage('Test, build and deploy Alfa-Client Helm Chart') { stage('Test, build and deploy Alfa-Client Helm Chart') {
steps { steps {
script { script {
dir('alfa-client') {
FAILED_STAGE=env.STAGE_NAME FAILED_STAGE=env.STAGE_NAME
HELM_CHART_VERSION = generateHelmChartVersion() HELM_CHART_VERSION = buildVersionName()
dir('alfa-client') {
sh "./run_helm_test.sh" sh "./run_helm_test.sh"
...@@ -295,7 +295,7 @@ pipeline { ...@@ -295,7 +295,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')]) {
...@@ -356,20 +356,27 @@ Void deployHelmChart(String helmChartVersion, String app ) { ...@@ -356,20 +356,27 @@ Void deployHelmChart(String helmChartVersion, String app ) {
} }
} }
String generateHelmChartVersion() { String validateBranchName(branchName) {
def chartVersion = "${VERSION}" int maxLength = 30
if (branchName.length() > maxLength) {
if (isMasterBranch()) { String originalBranchName = branchName
chartVersion += getCommitHash() 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()) { return branchName
chartVersion += "-barrierefreiheit${getCommitHash()}"
} }
else if (!isReleaseBranch()) {
chartVersion += "-${env.BRANCH_NAME}" String buildVersionName() {
if (isReleaseBranch()) {
return getRootPomVersion()
}
if (isBarrierefreiheitBranch()) {
return "${getRootPomVersion()}-barrierefreiheit${validateBranchName(env.BRANCH_NAME)}${getCommitHash()}".replaceAll("_", "-")
} }
return chartVersion.replaceAll("_", "-") return "${getRootPomVersion()}-${validateBranchName(env.BRANCH_NAME)}${getCommitHash()}".replaceAll("_", "-")
} }
Void tagAndPushDockerImage(String newTag){ Void tagAndPushDockerImage(String newTag){
...@@ -381,16 +388,6 @@ Void tagAndPushDockerImage(String newTag){ ...@@ -381,16 +388,6 @@ Void tagAndPushDockerImage(String newTag){
} }
} }
String generateImageTag() {
def imageTag = "${env.BRANCH_NAME}-${VERSION}"
if (isMasterBranch() || isBarrierefreiheitBranch()) {
imageTag += getCommitHash()
}
return imageTag
}
Void cloneGitopsRepo() { Void cloneGitopsRepo() {
withCredentials([usernamePassword(credentialsId: 'jenkins-gitea-access-token', passwordVariable: 'TOKEN', usernameVariable: 'USER')]) { 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' sh 'git clone https://${USER}:${TOKEN}@git.ozg-sh.de/ozgcloud-devops/gitops.git'
......
...@@ -89,7 +89,7 @@ pipeline { ...@@ -89,7 +89,7 @@ pipeline {
steps { steps {
script { script {
FAILED_STAGE=env.STAGE_NAME FAILED_STAGE=env.STAGE_NAME
IMAGE_TAG = generateImageTag() IMAGE_TAG = buildVersionName()
tagAndPushDockerImage(IMAGE_TAG) tagAndPushDockerImage(IMAGE_TAG)
...@@ -107,7 +107,7 @@ pipeline { ...@@ -107,7 +107,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('alfa-client/apps/admin') { dir('alfa-client/apps/admin') {
sh "./run_helm_test.sh" sh "./run_helm_test.sh"
...@@ -172,14 +172,22 @@ Boolean isReleaseBranch() { ...@@ -172,14 +172,22 @@ Boolean isReleaseBranch() {
return env.BRANCH_NAME == 'release-admin' return env.BRANCH_NAME == 'release-admin'
} }
String generateImageTag() { def validateBranchName(branchName) {
def imageTag = "${env.BRANCH_NAME}-${VERSION}" int maxLength = 30
if (branchName.length() > maxLength) {
if (isMasterBranch()) { String originalBranchName = branchName
imageTag += "-${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."
}
return branchName
} }
return imageTag String buildVersionName() {
if (isReleaseBranch()) {
return "${VERSION}"
}
return "${VERSION}-${validateBranchName(env.BRANCH_NAME)}-${env.GIT_COMMIT.take(7)}".replaceAll("_", "-")
} }
Void cloneGitopsRepo() { Void cloneGitopsRepo() {
...@@ -273,18 +281,6 @@ Void deployHelmChart(String helmChartVersion) { ...@@ -273,18 +281,6 @@ Void deployHelmChart(String helmChartVersion) {
} }
} }
} }
String generateHelmChartVersion() {
def chartVersion = "${VERSION}"
if (isMasterBranch()) {
chartVersion += "-${env.GIT_COMMIT.take(7)}"
}
else if (!isReleaseBranch()) {
chartVersion += "-${env.BRANCH_NAME}"
}
return chartVersion.replaceAll("_", "-")
}
Boolean isMasterBranch() { Boolean isMasterBranch() {
return env.BRANCH_NAME == 'master' return env.BRANCH_NAME == 'master'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment