-
Notifications
You must be signed in to change notification settings - Fork 225
/
Jenkinsfile_multibranch_pipeline
executable file
·87 lines (86 loc) · 3.24 KB
/
Jenkinsfile_multibranch_pipeline
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!groovy
pipeline {
agent {
label "$DITTO_BUILD_NODE"
}
parameters {
string(name: 'EXTRA_MAVEN_ARGS', defaultValue: '', description: 'Additional maven arguments.')
booleanParam(name: 'SKIP_SONAR_SCAN', defaultValue: false, description: 'Set to true to skip Sonarqube Scan.')
}
environment {
// Need to replace the '%2F' used by Jenkins to deal with / in the path (e.g. story/...)
theBranch = "${env.BRANCH_NAME}".replace("%2F", "-").replace("/", "-")
theVersion = "0-${theBranch}-SNAPSHOT"
theMvnRepo = "$WORKSPACE/../../.m2/feature-repository-${theBranch}"
JAVA_TOOL_OPTIONS = '-Duser.home=/home/jenkins-slave'
}
options {
buildDiscarder(logRotator(numToKeepStr: '10'))
disableConcurrentBuilds()
timeout(time: 1, unit: 'HOURS')
}
stages {
stage('Clean workspace and create local maven repository') {
steps {
echo 'Clean workspace'
cleanWs()
echo "Create local maven repository"
sh "mkdir -p ${theMvnRepo}"
}
}
stage('Checkout scm') {
steps {
echo 'Checkout scm'
checkout scm
}
}
stage('Build') {
agent {
docker {
args "$DITTO_DOCKER_ARGUMENTS"
image "$DITTO_DOCKER_IMAGE_MAVEN_JDK_17"
reuseNode true
}
}
steps {
configFileProvider([configFile(fileId: 'mvn-bdc-settings', variable: 'MVN_SETTINGS')]) {
sh "mvn -s $MVN_SETTINGS clean deploy javadoc:jar source:jar " +
"-T1C --batch-mode --errors " +
"-Pditto " +
"-Drevision=${theVersion} " +
"${params.EXTRA_MAVEN_ARGS ?: ''}"
}
}
post {
always {
junit "**/**/target/surefire-reports/*.xml,**/**/**/target/surefire-reports/*.xml,**/**/**/target/failsafe-reports/*.xml,**/**/target/failsafe-reports/*.xml"
}
}
}
stage('SonarQube Scan') {
agent {
docker {
args "$DITTO_DOCKER_ARGUMENTS"
image "$DITTO_DOCKER_IMAGE_MAVEN_JDK_17"
reuseNode true
}
}
when {
expression {
return !params.SKIP_SONAR_SCAN
}
}
steps {
configFileProvider([configFile(fileId: 'mvn-bdc-settings', variable: 'MVN_SETTINGS')]) {
echo 'Sonar Scan'
withSonarQubeEnv(installationName: "${env.SONAR_QUBE_ENV}", credentialsId: 'sonarqube') {
sh "mvn -s $MVN_SETTINGS --batch-mode --errors $SONAR_MAVEN_GOAL " +
"-Dsonar.host.url=$SONAR_HOST_URL " +
"-Dsonar.projectKey=org.eclipse.ditto:${theBranch} " +
"-Drevision=${theVersion}"
}
}
}
}
}
}