-
Notifications
You must be signed in to change notification settings - Fork 5
/
Jenkinsfile
148 lines (131 loc) · 5.56 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
#!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: 'rpminspect',
pipelineDescription: 'Run rpminspect on RPM builds',
testCategory: 'static-analysis',
testType: 'rpminspect',
maintainer: 'Fedora CI',
docs: 'https://rpminspect.readthedocs.io/en/latest/',
contact: [
irc: '#fedora-ci',
email: 'ci@lists.fedoraproject.org'
],
]
def artifactId
def testingFarmRequestId
def testingFarmResult
def repoUrlAndRef
def pipelineRepoUrlAndRef
def hook
def runUrl
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: 'TEST_PROFILE', defaultValue: env.DEFAULT_TEST_PROFILE, trim: true, description: "A name of the test profile to use; Example: ${env.DEFAULT_TEST_PROFILE}")
}
environment {
TESTING_FARM_API_KEY = credentials('testing-farm-api-key')
}
stages {
stage('Prepare') {
agent {
label pipelineMetadata.pipelineName
}
steps {
script {
artifactId = params.ARTIFACT_ID
setBuildNameFromArtifactId(artifactId: artifactId, profile: params.TEST_PROFILE)
checkout scm
config = loadConfig(profile: params.TEST_PROFILE)
if (!artifactId) {
abort('ARTIFACT_ID is missing')
}
repoUrlAndRef = getRepoUrlAndRefFromTaskId(getIdFromArtifactId(artifactId: artifactId))
pipelineRepoUrlAndRef = [url: "${getGitUrl()}", ref: "${getGitRef()}"]
}
sendMessage(type: 'queued', artifactId: artifactId, pipelineMetadata: pipelineMetadata, dryRun: isPullRequest())
}
}
stage('Schedule Test') {
agent {
label pipelineMetadata.pipelineName
}
steps {
script {
def requestPayload = [
api_key: "${env.TESTING_FARM_API_KEY}",
test: [
fmf: pipelineRepoUrlAndRef
],
environments: [
[
arch: "x86_64",
variables: [
PREVIOUS_TAG: "${config.previous_tag}",
TASK_ID: "${getIdFromArtifactId(artifactId: artifactId)}",
DEFAULT_RELEASE_STRING: "${config.default_release_string}",
REPOSITORY_URL: "${repoUrlAndRef.url}",
CONFIG_BRANCHES: "${config.config_branch}",
GIT_COMMIT: "${repoUrlAndRef.ref}",
RPMINSPECT_PROFILE_NAME: "${config.profile_name}",
DEBUG: "off"
]
]
]
]
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 {
sendMessage(type: 'complete', artifactId: artifactId, pipelineMetadata: pipelineMetadata, runUrl: runUrl, dryRun: isPullRequest())
}
failure {
sendMessage(type: 'error', artifactId: artifactId, pipelineMetadata: pipelineMetadata, runUrl: runUrl, dryRun: isPullRequest())
}
unstable {
sendMessage(type: 'complete', artifactId: artifactId, pipelineMetadata: pipelineMetadata, runUrl: runUrl, dryRun: isPullRequest())
}
}
}