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

OZG-3140 jenkinsfile new jenkins

parent 50be4753
No related branches found
No related tags found
No related merge requests found
pipeline { pipeline {
agent { agent {
node { node {
label 'jenkins-build-agent' label 'jenkins-quarkus-build-agent'
} }
} }
environment { environment {
BLUE_OCEAN_URL = "https://jenkins.ozg-sh.de/blue/organizations/jenkins/user-manager/detail/${env.BRANCH_NAME}/${env.BUILD_NUMBER}/pipeline" BLUE_OCEAN_URL = "https://jenkins.ozg-sh.de/job/user-manager/job/${env.BRANCH_NAME}/${env.BUILD_NUMBER}/"
RELEASE_REGEX = /\d+.\d+.\d+/ RELEASE_REGEX = /\d+.\d+.\d+/
SNAPSHOT_REGEX = /\d+.\d+.\d+-SNAPSHOT/ SNAPSHOT_REGEX = /\d+.\d+.\d+-SNAPSHOT/
FAILED_STAGE = "" FAILED_STAGE = ""
//The container runtime (e.g. docker) that is used to do an image based build. If this is set then a container build is always done. //The container runtime (e.g. docker) that is used to do an image based build. If this is set then a container build is always done.
QUARKUS_NATIVE_CONTAINER_RUNTIME = "podman" QUARKUS_NATIVE_CONTAINER_RUNTIME = "docker"
QUARKUS_CONTAINER_IMAGE_NAME = "user-manager" QUARKUS_CONTAINER_IMAGE_NAME = "user-manager"
QUARKUS_CONTAINER_IMAGE_TAG = "build-latest" QUARKUS_CONTAINER_IMAGE_TAG = "build-latest"
} }
...@@ -28,14 +28,9 @@ pipeline { ...@@ -28,14 +28,9 @@ pipeline {
steps { steps {
script { script {
FAILED_STAGE = env.STAGE_NAME FAILED_STAGE = env.STAGE_NAME
def rootPom = readMavenPom file: 'pom.xml' def rootVersion = getPomVersion('pom.xml')
def rootVersion = rootPom.version def userManagerVersion = getPomVersion('user-manager-server/pom.xml')
def interfaceVersion = getPomVersion('user-manager-interface/pom.xml')
def userManagerPom = readMavenPom file: 'user-manager-server/pom.xml'
def userManagerVersion = userManagerPom.version
def interfacePom = readMavenPom file: 'user-manager-interface/pom.xml'
def interfaceVersion = interfacePom.version
if(env.BRANCH_NAME == 'release'){ if(env.BRANCH_NAME == 'release'){
if ( !(rootVersion ==~ RELEASE_REGEX) || !(userManagerVersion ==~ RELEASE_REGEX) || !(interfaceVersion ==~ RELEASE_REGEX)) { if ( !(rootVersion ==~ RELEASE_REGEX) || !(userManagerVersion ==~ RELEASE_REGEX) || !(interfaceVersion ==~ RELEASE_REGEX)) {
...@@ -61,7 +56,7 @@ pipeline { ...@@ -61,7 +56,7 @@ pipeline {
} }
configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) { configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) {
sh 'mvn -pl user-manager-interface -s $MAVEN_SETTINGS clean deploy -Dmaven.wagon.http.retryHandler.count=3' sh './mvnw -pl user-manager-interface -s $MAVEN_SETTINGS clean deploy -Dmaven.wagon.http.retryHandler.count=3'
} }
} }
} }
...@@ -72,12 +67,7 @@ pipeline { ...@@ -72,12 +67,7 @@ pipeline {
FAILED_STAGE=env.STAGE_NAME FAILED_STAGE=env.STAGE_NAME
configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) { configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) {
def mavenConfig = sh script: 'echo $MAVEN_CONFIG', returnStdout: true
sh 'unset MAVEN_CONFIG'
sh './mvnw -pl user-manager-server -s $MAVEN_SETTINGS clean deploy -Dmaven.wagon.http.retryHandler.count=3' sh './mvnw -pl user-manager-server -s $MAVEN_SETTINGS clean deploy -Dmaven.wagon.http.retryHandler.count=3'
sh "export MAVEN_CONFIG=${mavenConfig}"
junit testResults: '**/target/surefire-reports/*.xml', skipPublishingChecks: true junit testResults: '**/target/surefire-reports/*.xml', skipPublishingChecks: true
} }
} }
...@@ -91,12 +81,7 @@ pipeline { ...@@ -91,12 +81,7 @@ pipeline {
withCredentials([usernamePassword(credentialsId: 'jenkins-nexus-login', usernameVariable: 'USER', passwordVariable: 'PASSWORD')]) { withCredentials([usernamePassword(credentialsId: 'jenkins-nexus-login', usernameVariable: 'USER', passwordVariable: 'PASSWORD')]) {
configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) { configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) {
def mavenConfig = sh script: 'echo $MAVEN_CONFIG', returnStdout: true sh './mvnw -pl user-manager-server -s $MAVEN_SETTINGS clean verify -Pnative -Dquarkus.container-image.registry=docker.ozg-sh.de -Dquarkus.container-image.username=${USER} -Dquarkus.container-image.password=${PASSWORD} -Dquarkus.container-image.push=true -Dquarkus.container-image.build=true -Dquarkus.native.remote-container-build=true -Dmaven.wagon.http.retryHandler.count=3'
sh 'unset MAVEN_CONFIG'
sh './mvnw -pl user-manager-server -s $MAVEN_SETTINGS clean verify -Pnative -Dquarkus.container-image.registry=docker.ozg-sh.de -Dquarkus.container-image.username=${USER} -Dquarkus.container-image.password=${PASSWORD} -Dquarkus.container-image.push=true -Dquarkus.container-image.build=true -Dmaven.wagon.http.retryHandler.count=3'
sh "export MAVEN_CONFIG=${mavenConfig}"
} }
} }
} }
...@@ -105,19 +90,17 @@ pipeline { ...@@ -105,19 +90,17 @@ pipeline {
stage('Sonar Checks') { stage('Sonar Checks') {
steps { steps {
when {
branch 'master'
}
script { script {
FAILED_STAGE=env.STAGE_NAME FAILED_STAGE=env.STAGE_NAME
}
configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) { configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) {
dir('user-manager-server') { dir('user-manager-server') {
script {
try { try {
if (env.BRANCH_NAME == 'master') {
withSonarQubeEnv('sonarqube-ozg-sh'){ withSonarQubeEnv('sonarqube-ozg-sh'){
def workspace = WORKSPACE sh "./mvnw -s $MAVEN_SETTINGS test sonar:sonar -Dsonar.coverage.jacoco.xmlReportPaths=${env.WORKSPACE}/user-manager-server/target/jacoco-report/jacoco.xml"
sh "mvn -s $MAVEN_SETTINGS test sonar:sonar -Dsonar.coverage.jacoco.xmlReportPaths=${env.WORKSPACE}/user-manager-server/target/jacoco-report/jacoco.xml"
}
} }
} catch (Exception e) { } catch (Exception e) {
unstable("SonarQube failed") unstable("SonarQube failed")
...@@ -216,10 +199,10 @@ pipeline { ...@@ -216,10 +199,10 @@ pipeline {
Void deployHelmChart(String helmChartVersion) { Void deployHelmChart(String helmChartVersion) {
withCredentials([usernamePassword(credentialsId: 'jenkins-nexus-login', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]){ withCredentials([usernamePassword(credentialsId: 'jenkins-nexus-login', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]){
if (env.BRANCH_NAME == 'release') { if (env.BRANCH_NAME == 'release') {
result = sh script: '''curl -u $USERNAME:$PASSWORD http://nexus.dev-tools:8081/service/rest/v1/components?repository=ozg-base-apps -F file=@user-manager-'''+helmChartVersion+'''.tgz''', returnStdout: true result = sh script: '''curl -u $USERNAME:$PASSWORD https://nexus.ozg-sh.de/service/rest/v1/components?repository=ozg-base-apps -F file=@user-manager-'''+helmChartVersion+'''.tgz''', returnStdout: true
} }
else { else {
result = sh script: '''curl -u $USERNAME:$PASSWORD http://nexus.dev-tools:8081/service/rest/v1/components?repository=ozg-base-apps-snapshot -F file=@user-manager-'''+helmChartVersion+'''.tgz''', returnStdout: true result = sh script: '''curl -u $USERNAME:$PASSWORD https://nexus.ozg-sh.de/service/rest/v1/components?repository=ozg-base-apps-snapshot -F file=@user-manager-'''+helmChartVersion+'''.tgz''', returnStdout: true
} }
if (result != '') { if (result != '') {
...@@ -328,10 +311,10 @@ String generateImageTag() { ...@@ -328,10 +311,10 @@ String generateImageTag() {
Void tagAndPushDockerImage(String newTag) { Void tagAndPushDockerImage(String newTag) {
withCredentials([usernamePassword(credentialsId: 'jenkins-nexus-login', usernameVariable: 'USER', passwordVariable: 'PASSWORD')]) { withCredentials([usernamePassword(credentialsId: 'jenkins-nexus-login', usernameVariable: 'USER', passwordVariable: 'PASSWORD')]) {
sh 'podman login docker.ozg-sh.de -u ${USER} -p ${PASSWORD}' sh 'docker login docker.ozg-sh.de -u ${USER} -p ${PASSWORD}'
sh "podman pull docker.ozg-sh.de/root/user-manager:build-latest" sh "docker pull docker.ozg-sh.de/root/user-manager:build-latest"
sh "podman tag docker.ozg-sh.de/root/user-manager:build-latest docker.ozg-sh.de/user-manager:${newTag}" sh "docker tag docker.ozg-sh.de/root/user-manager:build-latest docker.ozg-sh.de/user-manager:${newTag}"
sh "podman push docker.ozg-sh.de/user-manager:${newTag}" sh "docker push docker.ozg-sh.de/user-manager:${newTag}"
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment