-
Notifications
You must be signed in to change notification settings - Fork 129
/
Jenkinsfile
123 lines (109 loc) · 4.42 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
115
116
117
118
119
120
121
122
123
#!groovy
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
def AGENT_LABEL = env.AGENT_LABEL ?: 'ubuntu'
def JDK_NAME = env.JDK_NAME ?: 'jdk_1.8_latest'
def MVN_NAME = env.MVN_NAME ?: 'maven_3_latest'
// =================================================================
// https://cwiki.apache.org/confluence/display/INFRA/Jenkins
// https://cwiki.apache.org/confluence/display/INFRA/Multibranch+Pipeline+recipes
// =================================================================
// general pipeline documentation: https://jenkins.io/doc/book/pipeline/syntax/
pipeline {
// https://jenkins.io/doc/book/pipeline/syntax/#agent
agent {
node {
label AGENT_LABEL
}
}
tools {
maven MVN_NAME
jdk JDK_NAME
}
// https://jenkins.io/doc/book/pipeline/syntax/#options
options {
// support ANSI colors in stdout/stderr
ansiColor 'xterm'
// only keep the latest 10 builds
buildDiscarder logRotator(numToKeepStr: '10')
// cancel build if not complete within two hours of scheduling
timeout time: 3, unit: 'HOURS'
disableConcurrentBuilds()
}
environment {
LANG = 'C.UTF-8'
// --batch-mode Run in non-interactive (batch) mode
// --error Produce execution error messages
// --fail-at-end Only fail the build afterwards; allow all non-impacted builds to continue
// --show-version Display version information WITHOUT stopping build
// --no-transfer-progress Do not display transfer progress when downloading or uploading
MAVEN_CLI_OPTS = "--batch-mode --errors --fail-at-end --show-version --no-transfer-progress"
// https://cwiki.apache.org/confluence/display/INFRA/SonarQube+Analysis
// https://sonarcloud.io/documentation/analysis/scan/sonarscanner-for-maven/
SONARCLOUD_PARAMS = "-Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=apache -Dsonar.projectKey=apache_gora"
}
stages {
stage('Build') {
steps {
sh "mvn $MAVEN_CLI_OPTS -DskipTests clean install"
}
post {
success {
archiveArtifacts '**/target/*.jar'
}
}
}
stage('Test') {
steps {
warnError(message: "Failure during tests execution") {
sh "mvn $MAVEN_CLI_OPTS verify"
}
}
post {
always {
junit testResults: '**/target/surefire-reports/TEST-*.xml'
}
}
}
stage('Deploy snapshots') {
when {
branch 'master'
}
steps {
// Use release profile defined in project pom.xml
sh "mvn $MAVEN_CLI_OPTS --activate-profiles release -DskipTests deploy"
}
}
stage('Code Quality') {
// https://sonarcloud.io/documentation/appendices/move-analysis-java-11/
// "continue building in Java 8 but will use Java 11 to scan the code"
// https://cwiki.apache.org/confluence/display/INFRA/JDK+Installation+Matrix
tools {
jdk 'jdk_11_latest'
}
steps {
echo 'Checking Code Quality on SonarCloud'
// 'drazzib-sonarcloud-token' needs to be defined for this job and contains the user token
withCredentials([string(credentialsId: 'drazzib-sonarcloud-token', variable: 'SONAR_TOKEN')]) {
sh "mvn sonar:sonar ${SONARCLOUD_PARAMS} -Dsonar.branch.name=${BRANCH_NAME}"
}
}
}
}
}