From a293c6bad932a5b8ce35767c6738ed525c8afdb8 Mon Sep 17 00:00:00 2001
From: OZGCloud <ozgcloud@mgm-tp.com>
Date: Mon, 8 Jul 2024 18:43:52 +0200
Subject: [PATCH] OZG-5907 update jenkinsfile to upload jars from branches

---
 Jenkinsfile | 34 ++++++++++++++++++++++++++++------
 1 file changed, 28 insertions(+), 6 deletions(-)

diff --git a/Jenkinsfile b/Jenkinsfile
index 23aa689..dec4cc5 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -49,6 +49,26 @@ pipeline {
                 }
             }
         }*/
+       stage('Set Version') {
+          when {
+            not {
+                anyOf {
+                    branch 'master'
+                    branch 'release'
+                }
+            }
+          }
+          steps {
+                script {
+                    FAILED_STAGE=env.STAGE_NAME
+                    JAR_TAG = getPomVersion('pom.xml').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 OzgCloud-Common Dependencies') {
              steps {
                 script {
@@ -91,18 +111,14 @@ pipeline {
          }
 
         stage('Deploy OzgCloud-Common to Nexus'){
-            when {
-                anyOf {
-                    branch 'master'
-                    branch 'release'
-                }
-            }
+
             steps {
                 script {
                     FAILED_STAGE = env.STAGE_NAME
                 }
                 configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) {
                     sh 'mvn --no-transfer-progress -s $MAVEN_SETTINGS deploy'
+                    sh "mvn -s $MAVEN_SETTINGS versions:revert"
                 }
             }
         }
@@ -140,3 +156,9 @@ String getElementAccessToken() {
         return readJSON ( text: sh (script: '''curl -XPOST -d \"$LOGIN_JSON\" https://matrix.ozg-sh.de/_matrix/client/v3/login''', returnStdout: true)).access_token
     }
 }
+
+String getPomVersion(String pomFile){
+    def pom = readMavenPom file: pomFile
+
+    return pom.version
+}
\ No newline at end of file
-- 
GitLab