forked from elastic/ecs-logging-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
155 lines (152 loc) · 4.87 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env groovy
@Library('apm@current') _
pipeline {
agent any
environment {
REPO = 'ecs-logging-java'
BASE_DIR = "src/github.com/elastic/${env.REPO}"
NOTIFY_TO = credentials('notify-to')
JOB_GCS_BUCKET = credentials('gcs-bucket')
DOCKERHUB_SECRET = 'secret/apm-team/ci/elastic-observability-dockerhub'
MAVEN_CONFIG = '-Dmaven.repo.local=.m2'
JAVA_HOME = "${env.HUDSON_HOME}/.java/java11"
HOME = "${env.WORKSPACE}"
PATH = "${env.HOME}/bin:${env.JAVA_HOME}/bin:${env.PATH}"
}
options {
timeout(time: 1, unit: 'HOURS')
buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20', daysToKeepStr: '30'))
timestamps()
ansiColor('xterm')
disableResume()
durabilityHint('PERFORMANCE_OPTIMIZED')
rateLimitBuilds(throttle: [count: 60, durationName: 'hour', userBoost: true])
quietPeriod(10)
}
triggers {
issueCommentTrigger('(?i).*(?:jenkins\\W+)?run\\W+(?:the\\W+)?tests(?:\\W+please)?.*')
}
parameters {
string(name: 'MAVEN_CONFIG', defaultValue: '-B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn', description: 'Additional maven options.')
booleanParam(name: 'Run_As_Master_Branch', defaultValue: false, description: 'Allow to run any steps on a PR, some steps normally only run on master branch.')
booleanParam(name: 'test_ci', defaultValue: true, description: 'Enable test')
booleanParam(name: 'doc_ci', defaultValue: true, description: 'Enable doc validation')
}
stages {
stage('Initializing'){
agent { label 'linux && immutable' }
options { skipDefaultCheckout() }
environment {
MAVEN_CONFIG = "${params.MAVEN_CONFIG} ${env.MAVEN_CONFIG}"
}
stages {
/**
Checkout the code and stash it, to use it on other stages.
*/
stage('Checkout') {
steps {
deleteDir()
gitCheckout(basedir: env.BASE_DIR, githubNotifyFirstTimeContributor: true)
stash allowEmpty: true, name: 'source', useDefaultExcludes: false
}
}
/**
Build on a linux environment.
*/
stage('Build') {
options { skipDefaultCheckout() }
steps {
withGithubNotify(context: 'Build', tab: 'artifacts') {
deleteDir()
unstash 'source'
dir(BASE_DIR){
sh """#!/bin/bash
set -euxo pipefail
./mvnw clean install -DskipTests=true -Dmaven.javadoc.skip=true
./mvnw license:aggregate-third-party-report -Dlicense.excludedGroups=^co\\.elastic\\.
"""
archiveArtifacts allowEmptyArchive: true, onlyIfSuccessful: true,
artifacts: 'target/site/aggregate-third-party-report.html'
}
stash allowEmpty: true, name: 'build', useDefaultExcludes: false
}
}
}
}
}
stage('Tests') {
environment {
MAVEN_CONFIG = "${params.MAVEN_CONFIG} ${env.MAVEN_CONFIG}"
}
parallel {
/**
Run only unit test.
*/
stage('Unit Tests') {
agent { label 'linux && immutable' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression { return params.test_ci }
}
steps {
withGithubNotify(context: 'Unit Tests', tab: 'tests') {
deleteDir()
unstash 'build'
dir(BASE_DIR){
sh './mvnw test'
}
}
}
post {
always {
junit(allowEmptyResults: true, keepLongStdio: true,
testResults: "${BASE_DIR}/**/junit-*.xml,${BASE_DIR}/**/TEST-*.xml")
}
}
}
/**
Build javadoc files.
*/
stage('Javadoc') {
agent { label 'linux && immutable' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression { return params.doc_ci }
}
steps {
withGithubNotify(context: 'Javadoc') {
deleteDir()
unstash 'build'
dir(BASE_DIR){
sh './mvnw compile javadoc:javadoc'
}
}
}
}
/**
Build javadoc files.
*/
stage('Sanity checks') {
agent { label 'linux && immutable' }
options { skipDefaultCheckout() }
steps {
withGithubNotify(context: 'Sanity checks', tab: 'tests') {
deleteDir()
unstash 'source'
dir(BASE_DIR){
preCommit(commit: "${GIT_BASE_COMMIT}", junit: true)
}
}
}
}
}
}
}
post {
cleanup {
notifyBuildResult()
}
}
}