-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
114 lines (100 loc) · 4.15 KB
/
Jenkinsfile
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
pipeline {
agent {
kubernetes {
yamlFile 'kubernetesPod.yaml'
defaultContainer 'builder'
}
}
options {
buildDiscarder(logRotator(numToKeepStr: '3'))
}
stages {
stage('Load maven cache repository from S3') {
steps {
container('builder') {
sh """
aws --region 'eu-west-1' s3 sync s3://oa-phaedra2-jenkins-maven-cache/ /home/jenkins/maven-repository --quiet
"""
}
}
}
stage('Prepare environment') {
steps {
script {
env.GROUP_ID = sh(returnStdout: true, script: "mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.groupId -q -DforceStdout").trim()
env.ARTIFACT_ID = sh(returnStdout: true, script: "mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.artifactId -q -DforceStdout").trim()
env.VERSION = sh(returnStdout: true, script: "mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.version -q -DforceStdout").trim()
env.REGISTRY = "registry.openanalytics.eu"
env.MVN_ARGS = "-Dmaven.repo.local=/home/jenkins/maven-repository --batch-mode"
env.MVN_EXLCUDE_PARENT = ""
}
}
}
stage('Build') {
steps {
container('builder') {
configFileProvider([configFile(fileId: 'maven-settings-rsb', variable: 'MAVEN_SETTINGS_RSB')]) {
sh "mvn -s \$MAVEN_SETTINGS_RSB -U clean install -DskipTests -Ddocker.skip ${env.MVN_ARGS} ${env.MVN_EXLCUDE_PARENT}"
}
}
}
}
stage('Test') {
steps {
container('builder') {
withDockerRegistry([credentialsId: "oa-sa-jenkins-registry", url: "https://registry.openanalytics.eu"]) {
configFileProvider([configFile(fileId: 'maven-settings-rsb', variable: 'MAVEN_SETTINGS_RSB')]) {
sh "mvn -s \$MAVEN_SETTINGS_RSB test ${env.MVN_ARGS} ${env.MVN_EXLCUDE_PARENT}"
}
}
}
}
}
stage("Deploy to Nexus") {
steps {
container('builder') {
configFileProvider([configFile(fileId: 'maven-settings-rsb', variable: 'MAVEN_SETTINGS_RSB')]) {
sh "mvn -s \$MAVEN_SETTINGS_RSB deploy -DskipTests -Ddocker.skip ${env.MVN_ARGS} ${env.MVN_EXLCUDE_PARENT}"
}
}
}
}
stage('Build Docker image') {
steps {
container('builder') {
configFileProvider([configFile(fileId: 'maven-settings-rsb', variable: 'MAVEN_SETTINGS_RSB')]) {
sh "mvn -s \$MAVEN_SETTINGS_RSB docker:build ${env.MVN_ARGS}"
}
}
}
}
stage('Push to OA registry') {
steps {
container('builder') {
configFileProvider([configFile(fileId: 'maven-settings-rsb', variable: 'MAVEN_SETTINGS_RSB')]) {
sh "mvn -s \$MAVEN_SETTINGS_RSB docker:push -Ddocker.push.registry=${REGISTRY} ${env.MVN_ARGS}"
}
}
}
}
stage('Cache maven repository to S3') {
steps {
container('builder') {
sh """
aws --region 'eu-west-1' s3 sync /home/jenkins/maven-repository s3://oa-phaedra2-jenkins-maven-cache/ --quiet --exclude "*eu/openanalytics/*"
"""
}
}
}
}
post {
success {
step([$class: 'JacocoPublisher',
execPattern: '**/target/jacoco.exec',
classPattern: '**/target/classes',
sourcePattern: '**/src/main/java',
exclusionPattern: '**/src/test*'
])
}
}
}