diff --git a/Jenkinsfile b/Jenkinsfile index b27ddfbce5ed57f3f5e2bb498d5dffa497b7709f..376cdf69be6955e94ca8dc75f18041ed103aee2a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,6 +1,6 @@ def FAILED_STAGE -def E2E_FAILED def IMAGE_TAG +def VERSION pipeline { agent { @@ -13,6 +13,7 @@ pipeline { BLUE_OCEAN_URL = "https://jenkins.ozg-sh.de/blue/organizations/jenkins/goofy/detail/${env.BRANCH_NAME}/${env.BUILD_NUMBER}/pipeline" RELEASE_REGEX = /\d+.\d+.\d+/ SNAPSHOT_REGEX = /\d+.\d+.\d+-SNAPSHOT/ + E2E_FAILED = [] } options { @@ -22,11 +23,113 @@ pipeline { } stages { + stage('Check Version') { + steps { + script { + FAILED_STAGE = env.STAGE_NAME + def rootPom = readMavenPom file: 'pom.xml' + VERSION = rootPom.version + + def serverPom = readMavenPom file: 'goofy-server/pom.xml' + def serverVersion = serverPom.parent.version + + def clientPom = readMavenPom file: 'goofy-client/pom.xml' + def clientVersion = clientPom.parent.version + + if(env.BRANCH_NAME == 'release'){ + if ( !(VERSION ==~ RELEASE_REGEX) || !(serverVersion ==~ RELEASE_REGEX) || !(clientVersion ==~ RELEASE_REGEX)) { + error("Keine Release Version für Branch ${env.BRANCH_NAME}.") + } + } else { + if ( !(VERSION ==~ SNAPSHOT_REGEX) || !(serverVersion ==~ SNAPSHOT_REGEX) || !(clientVersion ==~ SNAPSHOT_REGEX)) { + error("Keine Snapshot Version für Branch ${env.BRANCH_NAME}.") + } + } + + if( !(VERSION == serverVersion && VERSION == clientVersion)){ + error("Versionen sind nicht identisch") + } + } + } + } + stage('Client') { + steps { + container("nodejs"){ + script { + FAILED_STAGE=env.STAGE_NAME + + sh 'npm --version' + dir('goofy-client') { + sh 'echo "registry=https://nexus.ozg-sh.de/repository/npm-proxy" >> ~/.npmrc' + sh 'echo "_auth=amVua2luczpQaihzX0ZNNFU5ZC8=" >> ~/.npmrc' + + sh 'npm install --no-optional' + + if (env.BRANCH_NAME == 'release') { + sh 'npm run ci-prodBuild' + } + else { + sh 'npm run ci-build' + } + + sh 'npm run ci-test' + + try { + if (env.BRANCH_NAME == 'master') { + withSonarQubeEnv('sonarqube-ozg-sh'){ + sh 'npm run ci-sonar' + } + } + } catch (Exception e) { + unstable("SonarQube failed") + } + } + } + } + } +// post { +// always{ +// junit testResults: 'goofy-client/test-report.xml', skipPublishingChecks: true +// } +// } + } + stage('Server') { + steps { + script { + FAILED_STAGE=env.STAGE_NAME + IMAGE_TAG = "${env.BRANCH_NAME}-${VERSION}" + println("IMAGE_TAG: ${IMAGE_TAG}") + + container("maven-17"){ + configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) { + sh 'mvn --version' + sh 'mvn -s $MAVEN_SETTINGS -pl -goofy-client clean install spring-boot:build-image -Dspring-boot.build-image.imageName=docker.ozg-sh.de/goofy:$IMAGE_TAG -Dspring-boot.build-image.publish -Dmaven.wagon.http.retryHandler.count=3' + } + + try { + if (env.BRANCH_NAME == 'master') { + dir('goofy-server'){ + withSonarQubeEnv('sonarqube-ozg-sh'){ + sh 'mvn sonar:sonar' + } + } + } + } catch (Exception e) { + unstable("SonarQube failed") + } + } + } + } + post { + always{ + junit testResults: '**/target/surefire-reports/*.xml', skipPublishingChecks: true + } + } + } stage('Init k8s') { steps { script { FAILED_STAGE = env.STAGE_NAME - IMAGE_TAG = 'latest' } container("k8s") { configFileProvider([configFile(fileId: 'jenkins-kuby-kubeconfig', variable: 'KUBE_CONFIG')]) { @@ -35,11 +138,6 @@ pipeline { } sh 'helm version' - } - container('nodejs') { - dir('goofy-client') { - sh 'npm install --no-optional' - } } } } @@ -47,11 +145,7 @@ pipeline { failFast false parallel { - stage('E2E-EA') { - when { - branch 'ozg-1784' - } - + stage('E2E-EA') { steps { script { def stageName = env.STAGE_NAME @@ -68,9 +162,8 @@ pipeline { } ) - if(runTests(stageName, 'einheitlicher-ansprechpartner') != '0') { - E2E_FAILED = true + E2E_FAILED += [stageName] } shutdownEnvironment(namespace) @@ -86,14 +179,18 @@ pipeline { reportFiles: 'report.html', reportName: "Goofy E2E-Tests EA" ]) + + script { + println('post E2E-EA') + println(env.STAGE_NAME) + if (E2E_FAILED.contains(env.STAGE_NAME)) { + currentBuild.result = 'FAILURE' + } + } } } } stage('E2E-main') { - when { - branch 'ozg-1784' - } - steps { script { def stageName = env.STAGE_NAME @@ -111,7 +208,7 @@ pipeline { ) if(runTests(stageName, 'main-tests') != '0') { - E2E_FAILED = true + E2E_FAILED += [stageName] } shutdownEnvironment(namespace) @@ -127,6 +224,14 @@ pipeline { reportFiles: 'report.html', reportName: "Goofy E2E-Tests main" ]) + + script { + println('post E2E-main') + println(env.STAGE_NAME) + if (E2E_FAILED.contains(env.STAGE_NAME)) { + currentBuild.result = 'FAILURE' + } + } } } } @@ -135,12 +240,104 @@ pipeline { always { script { if (E2E_FAILED) { - currentBuild.result = 'FAILURE' + FAILED_STAGE = "E2E (${E2E_FAILED.join(', ')})" } } } } } + stage('Deploy Maven Artifacts to Nexus') { + when { + anyOf { + branch 'master' + branch 'release' + } + } + steps { + script { + FAILED_STAGE = env.STAGE_NAME + } + container('maven-17') { + configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) { + sh 'mvn -s $MAVEN_SETTINGS -pl -goofy-client -DskipTests deploy' + } + } + } + } + stage('Deploy Goofy') { + when { + anyOf { + branch 'master' + branch 'release' + } + } + + steps { + script { + FAILED_STAGE = env.STAGE_NAME + } + container("docker") { + script { + withCredentials([usernamePassword(credentialsId: 'jenkins-docker-login', usernameVariable: 'USER', passwordVariable: 'PASSWORD')]) { + sh 'docker login docker.ozg-sh.de -u ${USER} -p ${PASSWORD}' + + if (env.BRANCH_NAME == 'release') { + sh 'docker tag docker.ozg-sh.de/goofy:${IMAGE_TAG} docker.ozg-sh.de/goofy:latest' + sh 'docker push docker.ozg-sh.de/goofy:latest' + } + + if (env.BRANCH_NAME == 'master') { + sh 'docker tag docker.ozg-sh.de/goofy:${IMAGE_TAG} docker.ozg-sh.de/goofy:snapshot-latest' + sh 'docker push docker.ozg-sh.de/goofy:snapshot-latest' + } + } + } + } + } + } + stage('Rollout (kiel-dev & ea-dev) | (kiel-test $ sl-test) Goofy') { + when { + anyOf { + branch 'master' + branch 'release' + } + } + + steps { + script { + FAILED_STAGE = env.STAGE_NAME + } + + container("k8s"){ + script { + if (env.BRANCH_NAME == 'release') { + sh 'kubectl rollout restart deployment/goofy -n sh-kiel-test' + sh 'kubectl rollout status deployment/goofy -n sh-kiel-test' + + sh 'kubectl rollout restart deployment/goofy -n sh-sl-test' + sh 'kubectl rollout status deployment/goofy -n sh-sl-test' + } + + if (env.BRANCH_NAME == 'master') { + sh 'kubectl rollout restart deployment/goofy -n sh-kiel-dev' + sh 'kubectl rollout status deployment/goofy -n sh-kiel-dev' + + sh 'kubectl rollout restart deployment/goofy -n sh-ea-dev' + sh 'kubectl rollout status deployment/goofy -n sh-ea-dev' + } + } + } + } + } + } + post { + failure { + script { + if (env.BRANCH_NAME == 'master') { + slackSend(color: "danger", message: "Goofy: Build Failed. Stage: ${FAILED_STAGE} Build-ID: <${BLUE_OCEAN_URL}|${env.BUILD_NUMBER}>") + } + } + } } } diff --git a/goofy-server/pom.xml b/goofy-server/pom.xml index 71de80bd876adc7e323e4bdae12208a506f4da07..a703a5a230b1bfa5ed238532d64875a901202537 100644 --- a/goofy-server/pom.xml +++ b/goofy-server/pom.xml @@ -158,6 +158,15 @@ <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> + <configuration> + <docker> + <publishRegistry> + <username>${docker-username}</username> + <password>${docker-password}</password> + <url>${docker-url}</url> + </publishRegistry> + </docker> + </configuration> </plugin> <plugin>