Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
pipeline {
agent {
node {
label 'ozgcloud-jenkins-build-agent-jdk21'
}
}
environment {
BLUE_OCEAN_URL = "https://jenkins.infra.ozg-cloud.systems/job/nachrichten-manager/job/${env.BRANCH_NAME}/${env.BUILD_NUMBER}/"
RELEASE_REGEX = /\d+.\d+.\d+/
SNAPSHOT_REGEX = /\d+.\d+.\d+-SNAPSHOT/
FAILED_STAGE = ""
SH_SUCCESS_STATUS_CODE = 0
}
options {
timeout(time: 1, unit: 'HOURS')
disableConcurrentBuilds()
buildDiscarder(logRotator(numToKeepStr: '5'))
}
stages {
stage('Check Version') {
steps {
script {
FAILED_STAGE = env.STAGE_NAME
def rootVersion = getPomVersion('pom.xml')
def interfaceVersion = getPomVersion('nachrichten-manager-interface/pom.xml')
if(isReleaseBranch()){
if ( !(rootVersion ==~ RELEASE_REGEX) || !(interfaceVersion ==~ RELEASE_REGEX) ) {
error("Keine Release Version für Branch ${env.BRANCH_NAME}.")
}
} else {
if ( !(rootVersion ==~ SNAPSHOT_REGEX) || !(interfaceVersion ==~ SNAPSHOT_REGEX) ) {
error("Keine Snapshot Version für Branch ${env.BRANCH_NAME}.")
}
}
if( !(rootVersion == interfaceVersion) ){
error("Versionen sind nicht identisch")
}
}
}
}
stage('Build NachrichtenManager') {
steps {
script {
FAILED_STAGE=env.STAGE_NAME
}
configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) {
sh 'mvn --no-transfer-progress -s $MAVEN_SETTINGS clean install -Dmaven.wagon.http.retryHandler.count=3 -DelasticTests.disabled=true'
}
}
}
stage('Deploy to Nexus'){
when {
anyOf {
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 -DskipTests deploy -Dmaven.wagon.http.retryHandler.count=3'
}
}
}
stage ('OWASP Dependency-Check Vulnerabilities') {
steps {
dependencyCheck additionalArguments: '''
-o "./"
-s "./"
-f "ALL"
-d /dependency-check-data
--suppression dependency-check-supressions.xml
--noupdate
--disableKnownExploited
--disableArchive
--prettyPrint''', odcInstallation: 'dependency-check-owasp'
dependencyCheckPublisher pattern: 'dependency-check-report.xml'
}
}
stage('Sonar Checks') {
when {
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
}
steps {
script {
FAILED_STAGE=env.STAGE_NAME
configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) {
dir('nachrichten-manager-postfach-interface') {
try {
withSonarQubeEnv('sonarqube-ozg-sh'){
sh 'mvn -s $MAVEN_SETTINGS sonar:sonar'
}
} catch (Exception e) {
unstable("SonarQube failed")
}
}
dir('nachrichten-manager-server') {
try {
withSonarQubeEnv('sonarqube-ozg-sh'){
sh 'mvn -s $MAVEN_SETTINGS sonar:sonar'
}
} catch (Exception e) {
unstable("SonarQube failed")
}
}
}
}
}
}
}
post {
always{
junit testResults: '**/target/surefire-reports/*.xml', skipPublishingChecks: true
}
failure {
script {
if (env.BRANCH_NAME == 'master' || env.BRANCH_NAME == 'release') {
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
sendFailureMessage()
}
}
}
}
}
Boolean isReleaseBranch() {
return env.BRANCH_NAME == 'release'
}
String getPomVersion(String pomFile){
def pom = readMavenPom file: pomFile
return pom.version
}
Void sendFailureMessage() {
def room = ''
def data = """{"msgtype":"m.text", \
"body":"NachrichtenManager: Build Failed. Stage: ${FAILED_STAGE} Build-ID: ${env.BUILD_NUMBER}
Link: ${BLUE_OCEAN_URL}", \
"format": "org.matrix.custom.html", \
"formatted_body":"NachrichtenManager: Build Failed. Stage: ${FAILED_STAGE} Build-ID: <a
href='${BLUE_OCEAN_URL}'>${env.BUILD_NUMBER}</a>"}"""
room = "!iQPAvQIiRwRpNOszjw: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
}
}