-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathJenkinsfile
244 lines (220 loc) · 9.52 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#!groovy
retry (10) {
// load pipeline configuration into the environment
httpRequest("${FEDORA_CI_PIPELINES_CONFIG_URL}/environment").content.split('\n').each { l ->
l = l.trim(); if (l && !l.startsWith('#')) { env["${l.split('=')[0].trim()}"] = "${l.split('=')[1].trim()}" }
}
}
def pipelineMetadata = [
pipelineName: 'dist-git',
pipelineDescription: 'Run tier-0 tests from dist-git',
testCategory: 'functional',
testType: 'tier0',
maintainer: 'Fedora CI',
docs: 'https://github.com/fedora-ci/dist-git-pipeline',
contact: [
irc: '#fedora-ci',
email: '[email protected]'
],
]
def artifactId
def additionalArtifactIds
def testingFarmRequestId
def testingFarmResult
def config
def hook
def runUrl
def repoUrlAndRef
def repoTests
def testPlan
def reportSeparately = false
pipeline {
agent none
libraries {
lib("fedora-pipeline-library@${env.PIPELINE_LIBRARY_VERSION}")
}
options {
buildDiscarder(logRotator(daysToKeepStr: env.DEFAULT_DAYS_TO_KEEP_LOGS, artifactNumToKeepStr: env.DEFAULT_ARTIFACTS_TO_KEEP))
timeout(time: env.DEFAULT_PIPELINE_TIMEOUT_MINUTES, unit: 'MINUTES')
skipDefaultCheckout(true)
}
parameters {
string(name: 'ARTIFACT_ID', defaultValue: '', trim: true, description: '"koji-build:<taskId>" for Koji builds; Example: koji-build:46436038')
string(name: 'ADDITIONAL_ARTIFACT_IDS', defaultValue: '', trim: true, description: 'A comma-separated list of additional ARTIFACT_IDs')
string(name: 'TEST_PROFILE', defaultValue: env.FEDORA_CI_RAWHIDE_RELEASE_ID, trim: true, description: "A name of the test profile to use; Example: ${env.FEDORA_CI_RAWHIDE_RELEASE_ID}")
string(name: 'TEST_REPO_URL', defaultValue: '', trim: true, description: '(optional) URL to the repository containing tests; followed by "#<ref>", where <ref> is a commit hash; Example: https://src.fedoraproject.org/tests/selinux#ff0784e36758f2fdce3201d907855b0dd74064f9')
string(name: 'TEST_PLAN', defaultValue: '', trim: true, description: '(optional) name of the test plan to run; Example: /plans/regression')
}
environment {
TESTING_FARM_API_KEY = credentials('testing-farm-api-key')
}
stages {
stage('Prepare') {
agent {
label pipelineMetadata.pipelineName
}
steps {
script {
artifactId = params.ARTIFACT_ID
additionalArtifactIds = params.ADDITIONAL_ARTIFACT_IDS
setBuildNameFromArtifactId(artifactId: artifactId, profile: params.TEST_PROFILE)
testPlan = params.TEST_PLAN
checkout scm
config = loadConfig(profile: params.TEST_PROFILE)
if (!artifactId) {
abort('ARTIFACT_ID is missing')
}
if (!TEST_REPO_URL) {
repoUrlAndRef = getRepoUrlAndRefFromTaskId("${getIdFromArtifactId(artifactId: artifactId)}")
} else {
repoUrlAndRef = [url: TEST_REPO_URL.split('#')[0], ref: TEST_REPO_URL.split('#')[1]]
}
repoTests = repoHasTests(repoUrl: repoUrlAndRef['url'], ref: repoUrlAndRef['ref'], context: config.tmt_context[getTargetArtifactType(artifactId)])
if (!repoTests) {
abort("No dist-git tests (STI/TMT) were found in the repository ${repoUrlAndRef[0]}, skipping...")
}
if (!testPlan) {
// it doesn't make sense to report results separately if we are running only one test plan
reportSeparately = repoTests.ciConfig.get('resultsdb-testcase') == 'separate'
} else {
pipelineMetadata['testType'] = testPlan
}
if (reportSeparately && repoTests['type'] == 'fmf') {
// we want to report results separately, so we will just run this job for each test plan individually
repoTests['plans'].each { plan ->
build(
job: "${JOB_NAME}",
wait: false,
parameters: [
string(name: 'ARTIFACT_ID', value: params.ARTIFACT_ID),
string(name: 'ADDITIONAL_ARTIFACT_IDS', value: params.ADDITIONAL_ARTIFACT_IDS),
string(name: 'TEST_PROFILE', value: params.TEST_PROFILE),
string(name: 'TEST_REPO_URL', value: params.TEST_REPO_URL),
string(name: 'TEST_PLAN', value: plan),
]
)
}
abort("Separate tasks were scheduled for all test plans.")
}
}
sendMessage(
type: 'queued',
artifactId: artifactId,
pipelineMetadata: pipelineMetadata,
dryRun: isPullRequest()
)
}
}
stage('Schedule Test') {
agent {
label pipelineMetadata.pipelineName
}
steps {
script {
def artifacts = []
getIdFromArtifactId(artifactId: artifactId, additionalArtifactIds: additionalArtifactIds).split(',').each { taskId ->
if (taskId) {
artifacts.add([id: "${taskId}", type: "fedora-koji-build"])
}
}
def requestPayload = [
api_key: "${env.TESTING_FARM_API_KEY}",
test: [:],
environments: [
[
arch: "x86_64",
variables: [
KOJI_TASK_ID: "${getIdFromArtifactId(artifactId: artifactId)}"
],
os: [ compose: "${config.compose}" ],
artifacts: artifacts
]
]
]
if (repoTests['type'] == 'sti') {
// add playbooks to run
requestPayload['test']['sti'] = repoUrlAndRef
requestPayload['test']['sti']['playbooks'] = repoTests['files']
} else {
// tmt
requestPayload['test']['fmf'] = repoUrlAndRef
requestPayload['environments'][0]['tmt'] = [
context: config.tmt_context[getTargetArtifactType(artifactId)]
]
if (testPlan) {
requestPayload['test']['fmf']['name'] = testPlan
}
}
hook = registerWebhook()
requestPayload['notification'] = ['webhook': [url: hook.getURL()]]
def response = submitTestingFarmRequest(payloadMap: requestPayload)
testingFarmRequestId = response['id']
}
sendMessage(
type: 'running',
artifactId: artifactId,
pipelineMetadata: pipelineMetadata,
dryRun: isPullRequest()
)
}
}
stage('Wait for Test Results') {
agent none
steps {
script {
def response = waitForTestingFarm(requestId: testingFarmRequestId, hook: hook)
testingFarmResult = response.apiResponse
runUrl = "${FEDORA_CI_TESTING_FARM_ARTIFACTS_URL}/${testingFarmRequestId}"
}
}
}
}
post {
always {
evaluateTestingFarmResults(testingFarmResult)
}
aborted {
script {
if (isTimeoutAborted(timeout: env.DEFAULT_PIPELINE_TIMEOUT_MINUTES, unit: 'MINUTES')) {
sendMessage(
type: 'error',
artifactId: artifactId,
errorReason: 'Timeout has been exceeded, pipeline aborted.',
pipelineMetadata: pipelineMetadata,
dryRun: isPullRequest()
)
}
}
}
success {
script {
sendMessage(
type: 'complete',
artifactId: artifactId,
pipelineMetadata: pipelineMetadata,
runUrl: runUrl,
dryRun: isPullRequest()
)
}
}
failure {
sendMessage(
type: 'error',
artifactId: artifactId,
pipelineMetadata: pipelineMetadata,
dryRun: isPullRequest()
)
}
unstable {
script {
sendMessage(
type: 'complete',
artifactId: artifactId,
pipelineMetadata: pipelineMetadata,
runUrl: runUrl,
dryRun: isPullRequest()
)
}
}
}
}