diff --git a/Jenkinsfile b/Jenkinsfile index 691142c386bd539e9be6e8debbd0a49deb011376..3542de4c2a9ff856ac1bf78f457f3726e9c91c25 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -29,7 +29,7 @@ pipeline { } environment { - BLUE_OCEAN_URL = "https://jenkins.infra.ozg-cloud.systems/job/alfa/job/${env.BRANCH_NAME}/${env.BUILD_NUMBER}/" + BLUE_OCEAN_URL = "https://jenkins.infra.ozg-cloud.systems/job/codeSH_frontendclients/job/${env.BRANCH_NAME}/${env.BUILD_NUMBER}/" RELEASE_REGEX = /\d+.\d+.\d+/ SNAPSHOT_REGEX = /\d+.\d+.\d+-SNAPSHOT/ FAILED_STAGE = "" @@ -50,23 +50,17 @@ pipeline { steps { script { FAILED_STAGE = env.STAGE_NAME - VERSION = getRootPomVersion() - def serverVersion = getParentPomVersion('alfa-server/pom.xml') - def clientVersion = getParentPomVersion('alfa-client/pom.xml') + VERSION = getAlfaPackageJsonVersion() if(isReleaseBranch()){ - if ( !isReleaseVersion([VERSION, serverVersion, clientVersion]) ) { + if ( !isReleaseVersion([VERSION]) ) { error("Keine Release Version für Branch ${env.BRANCH_NAME}.") } } else { - if ( !isSnapshotVersion([VERSION, serverVersion, clientVersion]) ) { + if ( !isSnapshotVersion([VERSION]) ) { error("Keine Snapshot Version für Branch ${env.BRANCH_NAME}.") } } - - if( !isSameVersion([serverVersion, clientVersion], VERSION) ){ - error("Versionen sind nicht identisch") - } } } } @@ -87,7 +81,7 @@ pipeline { sh 'npm cache verify' sh 'npm install' - if (isMasterBranch()) { + if (isMainBranch()) { withSonarQubeEnv('sonarqube-ozg-sh'){ sh 'npm run ci-sonar' } @@ -122,87 +116,17 @@ pipeline { sh 'npm run ci-build-alfa-client-container' } - withCredentials([usernamePassword(credentialsId: 'jenkins-nexus-login', usernameVariable: 'USER', passwordVariable: 'PASSWORD')]) { - sh 'docker login docker.ozg-sh.de -u ${USER} -p ${PASSWORD}' - - sh "docker tag docker.ozg-sh.de/alfa-client:build-latest docker.ozg-sh.de/alfa-client:${IMAGE_TAG}" - sh "docker push docker.ozg-sh.de/alfa-client:${IMAGE_TAG}" - } + tagAndPushDockerImage('build-latest', IMAGE_TAG) } } } } } - stage('Set Version') { - when { - not { - anyOf { - branch 'master' - branch 'release' - } - } - } - steps { - script { - FAILED_STAGE=env.STAGE_NAME - JAR_TAG = getRootPomVersion().replace("SNAPSHOT", "${env.BRANCH_NAME}-SNAPSHOT") - } - configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) { - sh "mvn -s $MAVEN_SETTINGS versions:set -DnewVersion=${JAR_TAG} -DprocessAllModules=true" - - } - } - } - - stage('Build Server artefacts, build and push docker image') { - steps { - script { - FAILED_STAGE=env.STAGE_NAME - IMAGE_TAG = buildVersionName() - - configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) { - sh 'mvn --version' - sh "mvn -s $MAVEN_SETTINGS -pl -alfa-client clean install" - sh "mvn --no-transfer-progress -s $MAVEN_SETTINGS -pl -alfa-client spring-boot:build-image -Dspring-boot.build-image.imageName=docker.ozg-sh.de/alfa:${IMAGE_TAG} -Dspring-boot.build-image.publish -Dmaven.wagon.http.retryHandler.count=3" - - if (isMasterBranch()) { - try { - dir('alfa-service'){ - withSonarQubeEnv('sonarqube-ozg-sh'){ - sh 'mvn --no-transfer-progress -s $MAVEN_SETTINGS sonar:sonar' - } - } - } - catch (Exception e) { - unstable("SonarQube failed") - } - } - } - } - } - post { - always{ - junit testResults: '**/target/surefire-reports/*.xml', skipPublishingChecks: true - } - } - } - stage('Deploy Maven Artifacts to Nexus') { - steps { - script { - FAILED_STAGE = env.STAGE_NAME - } - - configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) { - sh 'mvn --no-transfer-progress -s $MAVEN_SETTINGS -pl -alfa-client -DskipTests deploy' - sh "mvn -s $MAVEN_SETTINGS versions:revert" - } - } - } stage('Tag and Push Docker Image') { when { anyOf { - branch 'master' + branch 'main' branch 'release' } } @@ -211,29 +135,11 @@ pipeline { script { FAILED_STAGE = env.STAGE_NAME - if (isMasterBranch()) { - tagAndPushDockerImage('snapshot-latest') + if (isMainBranch()) { + tagAndPushDockerImage(IMAGE_TAG, 'snapshot-latest') } else if (isReleaseBranch()) { - tagAndPushDockerImage('latest') - } - } - } - } - - stage('Test, build and deploy Alfa Helm Chart') { - steps { - script { - FAILED_STAGE=env.STAGE_NAME - HELM_CHART_VERSION = buildVersionName() - - sh "./run_helm_test.sh" - - dir('src/main/helm') { - - sh "helm package --version=${HELM_CHART_VERSION} ." - - deployHelmChart(HELM_CHART_VERSION, "alfa") + tagAndPushDockerImage(IMAGE_TAG, 'latest') } } } @@ -261,7 +167,7 @@ pipeline { stage('Trigger Dev rollout') { when { - branch 'master' + branch 'main' } steps { script { @@ -275,7 +181,6 @@ pipeline { } } - stage('Trigger Test rollout') { when { branch 'release' @@ -292,25 +197,6 @@ pipeline { } } - stage ('Deploy SBOM to DependencyTrack') { - steps { - script { - IMAGE_TAG = buildVersionName() - - configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) { - withCredentials([string(credentialsId: 'dependency-track-api-key', variable: 'API_KEY')]) { - - dir('alfa-server') { - catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') { - sh "mvn --no-transfer-progress -s $MAVEN_SETTINGS io.github.pmckeown:dependency-track-maven-plugin:upload-bom -Ddependency-track.apiKey=$API_KEY -Ddependency-track.projectVersion=${IMAGE_TAG} -Ddependency-track.dependencyTrackBaseUrl=https://dependency-track.ozg-sh.de" - } - } - } - } - } - } - } - stage ('Trigger Barrierefreiheit Rollout') { when { branch 'barrierefreiheit-dev' @@ -333,7 +219,7 @@ pipeline { post { failure { script { - if (isMasterBranch() || isReleaseBranch()) { + if (isMainBranch() || isReleaseBranch()) { sendFailureMessage() } } @@ -370,21 +256,21 @@ String validateBranchName(branchName) { String buildVersionName() { if (isReleaseBranch()) { - return getRootPomVersion() + return VERSION } if (isBarrierefreiheitBranch()) { - return "${getRootPomVersion()}-barrierefreiheit${validateBranchName(env.BRANCH_NAME)}${getCommitHash()}".replaceAll("_", "-") + return "${VERSION}-barrierefreiheit${validateBranchName(env.BRANCH_NAME)}${getCommitHash()}".replaceAll("_", "-") } - return "${getRootPomVersion()}-${validateBranchName(env.BRANCH_NAME)}${getCommitHash()}".replaceAll("_", "-") + return "${VERSION}-${validateBranchName(env.BRANCH_NAME)}${getCommitHash()}".replaceAll("_", "-") } -Void tagAndPushDockerImage(String newTag){ +Void tagAndPushDockerImage(String currentTag, String newTag){ withCredentials([usernamePassword(credentialsId: 'jenkins-nexus-login', usernameVariable: 'USER', passwordVariable: 'PASSWORD')]) { sh 'docker login docker.ozg-sh.de -u ${USER} -p ${PASSWORD}' - sh "docker tag docker.ozg-sh.de/alfa:${IMAGE_TAG} docker.ozg-sh.de/alfa:${newTag}" - sh "docker push docker.ozg-sh.de/alfa:${newTag}" + sh "docker tag docker.ozg-sh.de/alfa-client:${currentTag} docker.ozg-sh.de/alfa-client:${newTag}" + sh "docker push docker.ozg-sh.de/alfa-client:${newTag}" } } @@ -422,11 +308,11 @@ Void configureGit() { Void sendFailureMessage() { def room = '' def data = """{"msgtype":"m.text", \ - "body":"Alfa: Build Failed. Stage: ${FAILED_STAGE} Build-ID: ${env.BUILD_NUMBER} Link: ${BLUE_OCEAN_URL}", \ + "body":"Alfa-Client: Build Failed. Stage: ${FAILED_STAGE} Build-ID: ${env.BUILD_NUMBER} Link: ${BLUE_OCEAN_URL}", \ "format": "org.matrix.custom.html", \ - "formatted_body":"Alfa: Build Failed. Stage: ${FAILED_STAGE} Build-ID: <a href='${BLUE_OCEAN_URL}'>${env.BUILD_NUMBER}</a>"}""" + "formatted_body":"Alfa-Client: Build Failed. Stage: ${FAILED_STAGE} Build-ID: <a href='${BLUE_OCEAN_URL}'>${env.BUILD_NUMBER}</a>"}""" - if (isMasterBranch()) { + if (isMainBranch()) { room = "!iQPAvQIiRwRpNOszjw:matrix.ozg-sh.de" } else if (isReleaseBranch()) { @@ -452,10 +338,6 @@ Void setNewTestVersion() { } Void setNewGitopsVersion(String environment) { - def envFile = "${environment}/application/values/alfa-values.yaml" - def commitMessage = "jenkins rollout ${environment} alfa version ${IMAGE_TAG}"; - setNewAlfaGitopsVersion(envFile, commitMessage); - envFile = "${environment}/application/values/alfa-client-values.yaml" commitMessage = "jenkins rollout ${environment} alfa-client version ${IMAGE_TAG}"; setNewAlfaClientGitopsVersion(envFile, commitMessage); @@ -464,23 +346,7 @@ Void setNewGitopsVersion(String environment) { Void setNewBarrierefreiheitVersion() { def envFile = "dev/namespace/namespaces/by-barrierefreiheit-dev.yaml" def commitMessage = "jenkins rollout ${IMAGE_TAG} for Barrierefreiheit Dev" - setNewAlfaGitopsVersion(envFile, commitMessage); -} - -Void setNewAlfaGitopsVersion(String envFile, String commitMessage) { - dir("gitops") { - def envVersions = readYaml file: envFile - - envVersions.alfa.image.tag = IMAGE_TAG - envVersions.alfa.helm.version = HELM_CHART_VERSION - - writeYaml file: envFile, data: envVersions, overwrite: true - - if (hasValuesFileChanged(envFile)) { - sh "git add ${envFile}" - sh "git commit -m '${commitMessage}'" - } - } + setNewAlfaClientGitopsVersion(envFile, commitMessage); } Void setNewAlfaClientGitopsVersion(String envFile, String commitMessage) { @@ -511,8 +377,8 @@ Boolean isReleaseBranch() { return env.BRANCH_NAME == 'release' } -Boolean isMasterBranch() { - return env.BRANCH_NAME == 'master' +Boolean isMainBranch() { + return env.BRANCH_NAME == 'main' } Boolean isBarrierefreiheitBranch() { @@ -538,22 +404,9 @@ Boolean matchRegexVersion(List versions, String regex) { return true } -Boolean isSameVersion(List versions, String expectedVersion) { - for (version in versions) { - if ( version != expectedVersion ) { - return false - } - } - - return true -} - -String getRootPomVersion() { - def rootPom = readMavenPom file: 'pom.xml' - return rootPom.version -} - -String getParentPomVersion(String filePath) { - def pom = readMavenPom file: filePath - return pom.parent.version -} +String getAlfaPackageJsonVersion() { + def packageJSON = readJSON file: 'alfa-client/apps/alfa/package.json' + def packageJSONVersion = packageJSON.version + echo packageJSONVersion + return packageJSONVersion +} \ No newline at end of file diff --git a/Jenkinsfile.admin b/Jenkinsfile.admin index 328d865ae486af46a901005eda56df55e13dbc0f..5f3f5ae78e683a9da5135447c0f6afff2987bc2f 100644 --- a/Jenkinsfile.admin +++ b/Jenkinsfile.admin @@ -50,14 +50,22 @@ pipeline { steps { script { FAILED_STAGE = env.STAGE_NAME - dir('alfa-client') { - VERSION = getPackagejsonVersion() - } + VERSION = getAdminPackageJsonVersion() + + if(isReleaseBranch()){ + if ( !isReleaseVersion([VERSION]) ) { + error("Keine Release Version für Branch ${env.BRANCH_NAME}.") + } + } else { + if ( !isSnapshotVersion([VERSION]) ) { + error("Keine Snapshot Version für Branch ${env.BRANCH_NAME}.") + } + } } } } - stage('build admin client and its docker image') { + stage('Build admin client and its docker image') { steps { script { FAILED_STAGE=env.STAGE_NAME @@ -72,7 +80,7 @@ pipeline { } else { sh 'npm run ci-build-admin' } - if (isMasterBranch()) { + if (isMainBranch()) { withSonarQubeEnv('sonarqube-ozg-sh'){ sh 'npm run ci-sonar' } @@ -93,7 +101,7 @@ pipeline { tagAndPushDockerImage(IMAGE_TAG) - if (isMasterBranch()) { + if (isMainBranch()) { tagAndPushDockerImage('snapshot-latest') } else if (isReleaseBranch()) { @@ -125,7 +133,7 @@ pipeline { stage('Trigger Dev rollout') { when { - branch 'master' + branch 'main' } steps { script { @@ -159,7 +167,7 @@ pipeline { post { failure { script { - if (isMasterBranch() || isReleaseBranch()) { + if (isMainBranch() || isReleaseBranch()) { sendFailureMessage() } } @@ -260,8 +268,8 @@ Void tagAndPushDockerImage(String newTag){ sh "docker push docker.ozg-sh.de/admin-client:${newTag}" } } -String getPackagejsonVersion() { - def packageJSON = readJSON file: 'package.json' +String getAdminPackageJsonVersion() { + def packageJSON = readJSON file: 'alfa-client/apps/admin/package.json' def packageJSONVersion = packageJSON.version echo packageJSONVersion return packageJSONVersion @@ -282,8 +290,8 @@ Void deployHelmChart(String helmChartVersion) { } } -Boolean isMasterBranch() { - return env.BRANCH_NAME == 'master' +Boolean isMainBranch() { + return env.BRANCH_NAME == 'main' } Void sendFailureMessage() { @@ -293,7 +301,7 @@ Void sendFailureMessage() { "format": "org.matrix.custom.html", \ "formatted_body":"Admin-Client: Build Failed. Stage: ${FAILED_STAGE} Build-ID: <a href='${BLUE_OCEAN_URL}'>${env.BUILD_NUMBER}</a>"}""" - if (isMasterBranch()) { + if (isMainBranch()) { room = "!iQPAvQIiRwRpNOszjw:matrix.ozg-sh.de" } else if (isReleaseBranch()) {