Skip to content
Snippets Groups Projects
Select Git revision
  • 3bb8174b9594609a0e939b973f591f16b4b327e9
  • main default protected
  • OZG-7967-rename-admin
  • OZG-8271-fix-date-bug
  • OZG-7985-Statistik-Datenfreigabe
  • OZG-7970-AlfaCodeFlow
  • OZG-7856_schadcode_scanner
  • OZG-8305-Create-webpack-sbom
  • tooltip-improvements
  • ods-remove-class-inputs
  • release-info
  • release-administration
  • release
  • OZG-7714-UpgradeKeycloakDependencyTo25
  • OZG-8086-Admin-Datenanfrage-erstellen
  • OZG-8086-Datenanfrage-Umbenennung
  • mongodb-7-0-16-e2e
  • OZG-6220-Bescheid-speichern-ohne-Postfach
  • OZG-7922-KeycloakOperatorExceptions
  • OZG-8142-poc-cards
  • OZG-8086-E2E
  • 1.11.0-info
  • 1.11.0-administration
  • 2.26.0-alfa
  • 1.10.0-info
  • 1.10.0-administration
  • 2.25.0-alfa
  • 1.9.0-info
  • 1.9.0-administration
  • 2.24.0-alfa
  • 1.8.0-info
  • 1.8.0-administration
  • 2.23.0-alfa
  • 1.7.0-info
  • 1.7.0-administration
  • 2.22.0-alfa
  • 1.6.0-info
  • 1.6.0-administration
  • 2.21.0-alfa
  • 1.5.0-info
  • 1.5.0-administration
41 results

heading.stories.ts

Blame
  • Jenkinsfile 6.69 KiB
    def FAILED_STAGE
    
    pipeline {
        agent {
           node {
               label 'ozgcloud-jenkins-build-agent-jdk21'
            }
        }
    
        environment {
            BLUE_OCEAN_URL = "https://jenkins.infra.ozg-cloud.systems/job/ozgcloud-common/job/${env.BRANCH_NAME}/${env.BUILD_NUMBER}/"
            RELEASE_REGEX = /\d+.\d+.\d+/
            SNAPSHOT_REGEX = /\d+.\d+.\d+-SNAPSHOT/
        }
    
        options {
            timeout(time: 1, unit: 'HOURS')
            disableConcurrentBuilds()
            buildDiscarder(logRotator(numToKeepStr: '5'))
        }
    
        stages {
    /*        stage('Check Version') {
                steps {
                    script {
                        FAILED_STAGE = env.STAGE_NAME
                        def rootPom = readMavenPom file: 'pom.xml'
                        def rootVersion = rootPom.version
                        
                        def dependenciesPom = readMavenPom file: 'ozgcloud-common-dependencies/pom.xml'
                        def dependenciesVersion = dependenciesPom.parent.version
                        
                        def parentPom = readMavenPom file: 'ozgcloud-common-parent/pom.xml'
                        def parentVersion = parentPom.version
    
                        if(env.BRANCH_NAME == 'release'){
                            if ( !(rootVersion ==~ RELEASE_REGEX) || !(dependenciesVersion ==~ RELEASE_REGEX) || !(parentVersion ==~ RELEASE_REGEX)) {
                                error("Keine Release Version für Branch ${env.BRANCH_NAME}.")
                            }
                        } else {
                            if ( !(rootVersion ==~ SNAPSHOT_REGEX) || !(dependenciesVersion ==~ SNAPSHOT_REGEX) || !(parentVersion ==~ SNAPSHOT_REGEX)) {
                                error("Keine Snapshot Version für Branch ${env.BRANCH_NAME}.")
                            }
                        }
    
                        if( !(rootVersion == dependenciesVersion && rootVersion == parentVersion)){
                            error("Versionen sind nicht identisch")                        
                        }                    
                    }
                }
            }*/
           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"
                        script {
                            updateDependencyVersions(JAR_TAG)
                        }
                    }
              }
            }  
            stage('Build OzgCloud-Common Dependencies') {
                 steps {
                    script {
                        FAILED_STAGE=env.STAGE_NAME
                    }
               		dir('ozgcloud-common-dependencies') {
                      	configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) {
                           	sh 'mvn --version'
                           	sh 'mvn --no-transfer-progress -s $MAVEN_SETTINGS clean install'
                        }
                    }
                }                       
            }
    
            
            stage('Build OzgCloud-Common') {
                steps {
                    script {
                        FAILED_STAGE=env.STAGE_NAME
                    }
                    configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) {
                        sh 'mvn --version'
                        sh 'mvn --no-transfer-progress -s $MAVEN_SETTINGS clean install'
    
    	                script {
    	              	    dir('ozgcloud-common-lib') {
    	                    	try {
    	                            if (env.BRANCH_NAME == 'master') {
    	                                withSonarQubeEnv('sonarqube-ozg-sh'){
        					    			sh 'mvn sonar:sonar'	                                
    	                                }
    	                            }
    	                        } catch (Exception e) {
    	                            unstable("SonarQube failed")
    	                        }
    	                    }
    	                }
    	            }
                }
             }
    
            stage('Deploy OzgCloud-Common to Nexus'){
    
                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"
                    }
                }
            }
        }
        post {
            failure {
                script {
                    if (env.BRANCH_NAME == 'master' || env.BRANCH_NAME == 'release') {
                        sendFailureMessage()
                    }
                }
            }
        }
    }
    
    void updateDependencyVersions(String snapshotVersion) {
        def pom = readMavenPom file: 'pom.xml'
        if ( pom.properties['ozgcloud-common.version'] ==~ SNAPSHOT_REGEX ) {
            pom.properties['ozgcloud-common.version'] = snapshotVersion
            writeMavenPom model: pom, file: 'pom.xml'
    	}
        pom = readMavenPom file: 'ozgcloud-common-parent/pom.xml'
        if ( pom.properties['ozgcloud-common.version'] ==~ SNAPSHOT_REGEX ) {
            pom.properties['ozgcloud-common.version'] = snapshotVersion
            writeMavenPom model: pom, file: 'ozgcloud-common-parent/pom.xml'
    	}
    }
    
    Void sendFailureMessage() {
        def room = ''
        def data = """{"msgtype":"m.text", \
                        "body":"ozgcloud-common: Build Failed. Stage: ${FAILED_STAGE} Build-ID: ${env.BUILD_NUMBER} Link: ${BLUE_OCEAN_URL}", \
                        "format": "org.matrix.custom.html", \
                        "formatted_body":"ozgcloud-common: Build Failed. Stage: ${FAILED_STAGE} Build-ID: <a href='${BLUE_OCEAN_URL}'>${env.BUILD_NUMBER}</a>"}"""
           
        if (env.BRANCH_NAME == 'master') {
            room = "!GjqhmouBtnDbwUkAjx:matrix.ozg-sh.de"
        }
        else if (env.BRANCH_NAME == 'release') {
            room = "!oWZpUGTFsxkJIYNfYg:matrix.ozg-sh.de"
        }
    
        sh "curl -XPOST -H 'authorization: Bearer ${getElementAccessToken()}' -d '${data}' https://matrix.ozg-sh.de/_matrix/client/v3/rooms/$room/send/m.room.message"
    }
    
    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
    }