From ee495dcc72bf434283f143923a15c8684b22ed4e Mon Sep 17 00:00:00 2001 From: OZGCloud <ozgcloud@mgm-tp.com> Date: Fri, 30 Aug 2024 12:08:52 +0200 Subject: [PATCH] OZG-6227 update jenkinsfile to upload jars from branches --- Jenkinsfile | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f9a7d4b..9a0e68a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -39,6 +39,26 @@ pipeline { } } } //stage check version + 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') { steps { script { @@ -50,18 +70,14 @@ pipeline { } } //stage build stage('Deploy 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 -s $MAVEN_SETTINGS -Pdeploy -DskipTests deploy' + sh 'mvn -s $MAVEN_SETTINGS versions:revert' + } } } //stage deploy @@ -98,4 +114,10 @@ String getElementAccessToken() { withCredentials([string(credentialsId: 'element-login-json', variable: 'LOGIN_JSON')]) { 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