diff --git a/alfa-client/apps/info/Jenkinsfile b/alfa-client/apps/info/Jenkinsfile index 2b7619392b6b040108a0e5c81d7ba274cd0bd022..229598a17788d64294d7911a2fd10dacbc88d92c 100644 --- a/alfa-client/apps/info/Jenkinsfile +++ b/alfa-client/apps/info/Jenkinsfile @@ -43,13 +43,6 @@ pipeline { IMAGE_TAG = generateImageTag() - if (isMasterBranch()) { - IMAGE_TAG = "snapshot-latest" - } - else if (isReleaseBranch()) { - IMAGE_TAG = "latest" - } - loginToDockerRegistry() sh "INPUT_TAGS=${IMAGE_TAG} INPUT_IMAGES=docker.ozg-sh.de/info-client-by npx nx container info --configuration=production-by" @@ -60,6 +53,34 @@ pipeline { } } + stage('Tag and Push snapshot-latest Docker image') { + when { + branch 'master' + } + steps { + script { + FAILED_STAGE=env.STAGE_NAME + + tagAndPushDockerImage('snapshot-latest') + } + } + } + + stage('Tag and Push latest Docker image') { + when { + expression { + isReleaseBranch() + } + } + steps { + script { + FAILED_STAGE=env.STAGE_NAME + + tagAndPushDockerImage('latest') + } + } + } + stage('Test, build and deploy info-client HelmChart') { steps { script { @@ -169,31 +190,44 @@ Void setNewGitopsVersion(String environment) { envVersions.info_client.helm.version = HELM_CHART_VERSION writeYaml file: envFile, data: envVersions, overwrite: true + } +} + +Void pushDevGitopsRepo() { + pushNewGitopsVersion('dev') +} + +Void pushTestGitopsRepo() { + pushNewGitopsVersion('test') +} + +Void pushNewGitopsVersion(String environment) { + dir('gitops') { + if (!hasGitopsValuesFileChanged(environment)) { + return + } + + withCredentials([usernamePassword(credentialsId: 'jenkins-gitea-access-token', passwordVariable: 'TOKEN', usernameVariable: 'USER')]) { + sh "git add ${environment}/application/values/info-client-values.yaml" - if (hasValuesFileChanged(environment)) { - sh "git add ${envFile}" sh "git commit -m 'jenkins rollout ${environment} info-client version ${IMAGE_TAG}'" + sh 'git push https://${USER}:${TOKEN}@git.ozg-sh.de/ozgcloud-devops/gitops.git' } } } -Boolean hasValuesFileChanged(String environment) { +Boolean hasGitopsValuesFileChanged(String environment) { return sh (script: "git status | grep '${environment}/application/values/info-client-values.yaml'", returnStatus: true) == env.SH_SUCCESS_STATUS_CODE as Integer } +Void tagAndPushDockerImage(String newTag){ + loginToDockerRegistry() -Void pushGitopsRepo() { - withCredentials([usernamePassword(credentialsId: 'jenkins-gitea-access-token', passwordVariable: 'TOKEN', usernameVariable: 'USER')]) { - dir("gitops") { - if (hasUnpushedCommits()) { - sh 'git push https://${USER}:${TOKEN}@git.ozg-sh.de/ozgcloud-devops/gitops.git' - } - } - } -} + sh "docker tag docker.ozg-sh.de/info-client-by:${IMAGE_TAG} docker.ozg-sh.de/info-client-by:${newTag}" + sh "docker push docker.ozg-sh.de/info-client-by:${newTag}" -Boolean hasUnpushedCommits() { - return sh (script: "git cherry -v | grep .", returnStatus: true) == env.SH_SUCCESS_STATUS_CODE as Integer + sh "docker tag docker.ozg-sh.de/info-client-sh:${IMAGE_TAG} docker.ozg-sh.de/info-client-sh:${newTag}" + sh "docker push docker.ozg-sh.de/info-client-sh:${newTag}" } Void loginToDockerRegistry(){