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

OZG-1784 jenkinsfile

parent 3f562269
No related branches found
No related tags found
No related merge requests found
def FAILED_STAGE def FAILED_STAGE
def E2E_FAILED
def IMAGE_TAG def IMAGE_TAG
def VERSION
pipeline { pipeline {
agent { agent {
...@@ -13,6 +13,7 @@ pipeline { ...@@ -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" 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+/ RELEASE_REGEX = /\d+.\d+.\d+/
SNAPSHOT_REGEX = /\d+.\d+.\d+-SNAPSHOT/ SNAPSHOT_REGEX = /\d+.\d+.\d+-SNAPSHOT/
E2E_FAILED = []
} }
options { options {
...@@ -22,11 +23,113 @@ pipeline { ...@@ -22,11 +23,113 @@ pipeline {
} }
stages { 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') { stage('Init k8s') {
steps { steps {
script { script {
FAILED_STAGE = env.STAGE_NAME FAILED_STAGE = env.STAGE_NAME
IMAGE_TAG = 'latest'
} }
container("k8s") { container("k8s") {
configFileProvider([configFile(fileId: 'jenkins-kuby-kubeconfig', variable: 'KUBE_CONFIG')]) { configFileProvider([configFile(fileId: 'jenkins-kuby-kubeconfig', variable: 'KUBE_CONFIG')]) {
...@@ -35,11 +138,6 @@ pipeline { ...@@ -35,11 +138,6 @@ pipeline {
} }
sh 'helm version' sh 'helm version'
}
container('nodejs') {
dir('goofy-client') {
sh 'npm install --no-optional'
}
} }
} }
} }
...@@ -48,10 +146,6 @@ pipeline { ...@@ -48,10 +146,6 @@ pipeline {
parallel { parallel {
stage('E2E-EA') { stage('E2E-EA') {
when {
branch 'ozg-1784'
}
steps { steps {
script { script {
def stageName = env.STAGE_NAME def stageName = env.STAGE_NAME
...@@ -68,9 +162,8 @@ pipeline { ...@@ -68,9 +162,8 @@ pipeline {
} }
) )
if(runTests(stageName, 'einheitlicher-ansprechpartner') != '0') { if(runTests(stageName, 'einheitlicher-ansprechpartner') != '0') {
E2E_FAILED = true E2E_FAILED += [stageName]
} }
shutdownEnvironment(namespace) shutdownEnvironment(namespace)
...@@ -86,14 +179,18 @@ pipeline { ...@@ -86,14 +179,18 @@ pipeline {
reportFiles: 'report.html', reportFiles: 'report.html',
reportName: "Goofy E2E-Tests EA" 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'
} }
}
stage('E2E-main') {
steps { steps {
script { script {
def stageName = env.STAGE_NAME def stageName = env.STAGE_NAME
...@@ -111,7 +208,7 @@ pipeline { ...@@ -111,7 +208,7 @@ pipeline {
) )
if(runTests(stageName, 'main-tests') != '0') { if(runTests(stageName, 'main-tests') != '0') {
E2E_FAILED = true E2E_FAILED += [stageName]
} }
shutdownEnvironment(namespace) shutdownEnvironment(namespace)
...@@ -127,6 +224,14 @@ pipeline { ...@@ -127,6 +224,14 @@ pipeline {
reportFiles: 'report.html', reportFiles: 'report.html',
reportName: "Goofy E2E-Tests main" 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,11 +240,103 @@ pipeline { ...@@ -135,11 +240,103 @@ pipeline {
always { always {
script { script {
if (E2E_FAILED) { 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}>")
}
}
} }
} }
} }
......
...@@ -158,6 +158,15 @@ ...@@ -158,6 +158,15 @@
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <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>
<plugin> <plugin>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment