-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathJenkinsfile
150 lines (131 loc) · 6.3 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
#!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 releaseId
def sourceRepo
def kojiUrl
def taskId
def artifactId
def pipelineMetadata = [
pipelineName: 'dist-git',
pipelineDescription: 'Scratch-build Pull-Requests in Koji',
testCategory: 'validation',
testType: 'scratch-build',
maintainer: 'Fedora CI',
docs: 'https://github.com/fedora-ci/dist-git-build-pipeline',
contact: [
irc: '#fedora-ci',
email: 'ci@lists.fedoraproject.org'
],
]
pipeline {
agent {
label 'scratch-build'
}
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: 24, unit: 'HOURS')
}
parameters {
string(name: 'REPO_FULL_NAME', defaultValue: '', description: 'Full name of the target repository; for example: "rpms/jenkins"')
string(name: 'SOURCE_REPO_FULL_NAME', defaultValue: '', description: 'Full name of the source repository; for example: "fork/msrb/rpms/jenkins"')
string(name: 'TARGET_BRANCH', defaultValue: 'rawhide', description: 'Name of the target branch where the pull request should be merged')
string(name: 'PR_ID', defaultValue: '1', description: 'Pull-Request Id (number)')
string(name: 'PR_UID', defaultValue: '', description: "Pagure's unique internal pull-request Id")
string(name: 'PR_COMMIT', defaultValue: '', description: 'Commit Id (hash) of the last commit in the pull-request')
string(name: 'PR_COMMENT', defaultValue: '0', description: "Pagure's internal Id of the comment which triggered CI testing; 0 (zero) if the testing was triggered by simply opening the pull-request")
}
stages {
stage('Prepare') {
steps {
script {
if (!params.REPO_FULL_NAME) {
currentBuild.result = 'ABORTED'
error('Bad input, nothing to do.')
}
artifactId = "fedora-dist-git:${params.PR_UID}@${params.PR_COMMIT}#${params.PR_COMMENT}"
setBuildNameFromArtifactId(artifactId: artifactId)
sendMessage(type: 'queued', artifactId: artifactId, pipelineMetadata: pipelineMetadata, dryRun: isPullRequest())
if (TARGET_BRANCH != 'rawhide') {
// fallback to rawhide in case this is not a standard fedora (or epel) branch
releaseId = (params.TARGET_BRANCH ==~ /f\d+|epel\d+|epel\d+\-next/) ? params.TARGET_BRANCH : env.FEDORA_CI_RAWHIDE_RELEASE_ID
} else {
releaseId = env.FEDORA_CI_RAWHIDE_RELEASE_ID
}
sourceRepo = params.SOURCE_REPO_FULL_NAME
if (!sourceRepo) {
sourceRepo="${params.REPO_FULL_NAME}"
}
}
}
}
stage('Scratch-Build in Koji') {
environment {
KOJI_KEYTAB = credentials('fedora-keytab')
KRB_PRINCIPAL = 'bpeck/jenkins-continuous-infra.apps.ci.centos.org@FEDORAPROJECT.ORG'
}
steps {
script {
timeout(time: 240, unit: 'MINUTES') {
def rc = sh(returnStatus: true, script: "./scratch-build.sh koji ${releaseId}-candidate git+https://src.fedoraproject.org/${sourceRepo}.git#${params.PR_COMMIT}")
if (fileExists('koji_url')) {
kojiUrl = readFile("${env.WORKSPACE}/koji_url").trim()
}
if (fileExists('task_id')) {
taskId = readFile("${env.WORKSPACE}/task_id").trim()
}
catchError(buildResult: 'UNSTABLE') {
if (rc != 0) {
error('Failed to scratch build the pull request.')
}
}
sendMessage(type: 'running', artifactId: artifactId, pipelineMetadata: pipelineMetadata, dryRun: isPullRequest(), runUrl: kojiUrl)
// Wait for the scratch-build to finish
rc = sh(returnStatus: true, script: "./wait-build.sh ${taskId}")
catchError(buildResult: 'UNSTABLE') {
if (rc != 0) {
error("Scratch-build failed in Koji")
}
}
}
}
}
}
}
post {
success {
sendMessage(type: 'complete', artifactId: artifactId, pipelineMetadata: pipelineMetadata, dryRun: isPullRequest(), runUrl: kojiUrl)
// Run dist-git tests on the scratch build, and report results back to the pull request
build(
wait: false,
job: 'fedora-ci/dist-git-pipeline/master',
parameters: [
string(name: 'ARTIFACT_ID', value: "(koji-build:${taskId})->${artifactId}"),
string(name: 'TEST_PROFILE', value: releaseId)
]
)
// Run the installability test on the scratch build, and report results back to the pull request
build(
wait: false,
job: 'fedora-ci/installability-pipeline/master',
parameters: [
string(name: 'ARTIFACT_ID', value: "(koji-build:${taskId})->${artifactId}"),
string(name: 'TEST_PROFILE', value: releaseId)
]
)
}
failure {
sendMessage(type: 'error', artifactId: artifactId, pipelineMetadata: pipelineMetadata, dryRun: isPullRequest(), runUrl: kojiUrl)
}
unstable {
sendMessage(type: 'complete', artifactId: artifactId, pipelineMetadata: pipelineMetadata, dryRun: isPullRequest(), runUrl: kojiUrl)
}
}
}