This repository has been archived by the owner on Jan 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 68
/
Jenkinsfile
151 lines (145 loc) · 4.7 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
#!/usr/bin/env groovy
@Library('apm@current') _
pipeline {
agent none
environment {
BASE_DIR="src/github.com/elastic/apm-integration-testing"
NOTIFY_TO = credentials('notify-to')
JOB_GCS_BUCKET = credentials('gcs-bucket')
PIPELINE_LOG_LEVEL='INFO'
}
triggers {
cron 'H H(3-4) * * 1-5'
issueCommentTrigger('(?i).*(?:jenkins\\W+)?run\\W+(?:the\\W+)?tests(?:\\W+please)?.*')
}
options {
timeout(time: 1, unit: 'HOURS')
buildDiscarder(logRotator(numToKeepStr: '100', artifactNumToKeepStr: '100'))
timestamps()
ansiColor('xterm')
disableResume()
durabilityHint('PERFORMANCE_OPTIMIZED')
rateLimitBuilds(throttle: [count: 60, durationName: 'hour', userBoost: true])
quietPeriod(10)
}
parameters {
string(name: 'ELASTIC_STACK_VERSION', defaultValue: "8.0.0", description: "Elastic Stack Git branch/tag to use")
string(name: 'BUILD_OPTS', defaultValue: "", description: "Addicional build options to passing compose.py")
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.')
}
stages{
/**
Checkout the code and stash it, to use it on other stages.
*/
stage('Checkout'){
agent { label 'master || immutable' }
steps {
deleteDir()
gitCheckout(basedir: "${BASE_DIR}")
stash allowEmpty: true, name: 'source', useDefaultExcludes: false
}
}
stage('Tests'){
parallel {
/**
Validate UTs and lint the app
*/
stage('Unit Tests'){
agent { label 'linux && immutable && docker' }
steps {
withGithubNotify(context: 'Unit Tests', tab: 'tests') {
deleteDir()
unstash 'source'
dir("${BASE_DIR}"){
sh '.ci/scripts/unit-tests.sh'
}
}
}
post {
always {
junit(allowEmptyResults: true,
keepLongStdio: true,
testResults: "${BASE_DIR}/**/*junit.xml")
}
}
}
stage('Check pre-commit') {
agent { label 'linux && immutable && docker' }
environment {
PATH = "${env.WORKSPACE}/${env.BASE_DIR}/.ci/scripts:${env.WORKSPACE}/bin:${env.PATH}"
HOME = "${env.WORKSPACE}"
}
steps {
withGithubNotify(context: 'Check pre-commit') {
deleteDir()
unstash 'source'
dir("${BASE_DIR}"){
sh '''
env | sort
curl https://pre-commit.com/install-local.py | python -
git diff-tree --no-commit-id --name-only -r ${GIT_BASE_COMMIT} | xargs pre-commit run --files
'''
}
}
}
}
}
}
/**
launch integration tests.
*/
stage("Integration Tests") {
agent none
steps {
log(level: "INFO", text: "Launching Agent tests in parallel")
/*
Declarative pipeline's parallel stages lose the reference to the downstream job,
because of that, I use the parallel step. It is probably a bug.
https://issues.jenkins-ci.org/browse/JENKINS-56562
*/
script {
def downstreamJobs = [:]
if(env?.CHANGE_ID != null && !params.Run_As_Master_Branch){
downstreamJobs = ['All': {runJob('All')}]
} else {
downstreamJobs = [
'All': {runJob('All')},
'.NET': {runJob('.NET')},
'Go': {runJob('Go')},
'Java': {runJob('Java')},
'Node.js': {runJob('Node.js')},
'Python': {runJob('Python')},
'Ruby': {runJob('Ruby')},
'RUM': {runJob('RUM')},
'UI': {runJob('UI')}
]
}
parallel(downstreamJobs)
}
}
}
}
post {
cleanup {
notifyBuildResult()
}
}
}
def runJob(agentName, buildOpts = ''){
def branch = env.BRANCH_NAME
if (env.CHANGE_ID) {
branch = env.CHANGE_TARGET
}
def job = build(job: "apm-integration-test-downstream/${branch}",
parameters: [
string(name: 'AGENT_INTEGRATION_TEST', value: agentName),
string(name: 'ELASTIC_STACK_VERSION', value: params.ELASTIC_STACK_VERSION),
string(name: 'INTEGRATION_TESTING_VERSION', value: env.GIT_BASE_COMMIT),
string(name: 'MERGE_TARGET', value: "${branch}"),
string(name: 'BUILD_OPTS', value: "${params.BUILD_OPTS} ${buildOpts}"),
string(name: 'UPSTREAM_BUILD', value: currentBuild.fullDisplayName),
booleanParam(name: 'DISABLE_BUILD_PARALLEL', value: '')],
propagate: true,
quietPeriod: 10,
wait: true)
}