forked from CentOS-PaaS-SIG/upstream-fedora-pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JenkinsfileStageTrigger
207 lines (193 loc) · 9.82 KB
/
JenkinsfileStageTrigger
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
#!groovy
/**
* Upstream Fedora Stage Pipeline Trigger
*
* This is a declarative pipeline for the upstream fedora stage pipeline trigger
*
*/
// Openshift project
openshiftProject = "continuous-infra"
DOCKER_REPO_URL = '172.30.254.79:5000'
// Defaults for SCM operations
env.ghprbGhRepository = env.ghprbGhRepository ?: 'CentOS-PaaS-SIG/upstream-fedora-pipeline'
// git commit default
env.ghprbActualCommit = env.ghprbActualCommit ?: 'master'
// Fedora Fedmsg Message Provider for stage
MSG_PROVIDER = "FedoraMessagingStage"
// IRC properties
IRC_NICK = "contra-bot"
IRC_CHANNEL = "#contra-ci-cd"
STABLE_LABEL = 'stable'
tagMap = [:]
// Initialize
tagMap['jenkins-fedoraci-slave'] = STABLE_LABEL
tagMap['fedoraci-runner'] = STABLE_LABEL
// CI_MESSAGES known to build successfully
CANNED_CI_MESSAGES = [:]
CANNED_CI_MESSAGES['rawhide'] = '{"pullrequest":{"last_updated":"1557907130","uid":"b08cc62005f643a39fa66f7c4891dac4","initial_comment":null,"commit_stop":"1c474a3f55b792c378c6f1a0a8075335d87eff03","remote_git":null,"closed_at":null,"id":6,"title":"just dummy PR to use the patch on stage Fedora CI pipeline","comments":[],"branch":"master","status":"Open","tags":[],"user":{"fullname":"Bruno Goncalves","name":"bgoncalv"},"date_created":"1557907130","closed_by":null,"branch_from":"dummy-test","assignee":null,"commit_start":"1c474a3f55b792c378c6f1a0a8075335d87eff03","project":{"custom_keys":[],"description":"The ksh rpms","parent":null,"date_modified":"1507637032","access_users":{"admin":["mhlavink"],"commit":["kdudka"],"ticket":[],"owner":["svashisht"]},"namespace":"rpms","priorities":{},"id":7896,"access_groups":{"admin":[],"commit":[],"ticket":[]},"milestones":{},"user":{"fullname":"Siteshwar Vashisht","name":"svashisht"},"date_created":"1501870087","fullname":"rpms/ksh","url_path":"rpms/ksh","close_status":[],"tags":[],"name":"ksh"},"repo_from":{"custom_keys":[],"description":"The ksh rpms","parent":{"custom_keys":[],"description":"The ksh rpms","parent":null,"date_modified":"1507637032","access_users":{"admin":["mhlavink"],"commit":["kdudka"],"ticket":[],"owner":["svashisht"]},"namespace":"rpms","priorities":{},"id":7896,"access_groups":{"admin":[],"commit":[],"ticket":[]},"milestones":{},"user":{"fullname":"Siteshwar Vashisht","name":"svashisht"},"date_created":"1501870087","fullname":"rpms/ksh","url_path":"rpms/ksh","close_status":[],"tags":[],"name":"ksh"},"date_modified":"1557906960","access_users":{"admin":[],"commit":[],"ticket":[],"owner":["bgoncalv"]},"namespace":"rpms","priorities":{},"id":36015,"access_groups":{"admin":[],"commit":[],"ticket":[]},"milestones":{},"user":{"fullname":"Bruno Goncalves","name":"bgoncalv"},"date_created":"1557906960","fullname":"forks/bgoncalv/rpms/ksh","url_path":"fork/bgoncalv/rpms/ksh","close_status":[],"tags":[],"name":"ksh"},"cached_merge_status":"unknown","updated_on":"1557907130","threshold_reached":null},"agent":"bgoncalv"}'
def libraries = ['cico-pipeline' : ['master', 'https://github.com/CentOS/cico-pipeline-library.git'],
'contra-lib' : ['master', 'https://github.com/openshift/contra-lib']]
libraries.each { name, repo ->
library identifier: "${name}@${repo[0]}",
retriever: modernSCM([$class: 'GitSCMSource',
remote: repo[1]])
// Check out PR's version of library
library identifier: "upstream-fedora-pipeline@${env.ghprbActualCommit}",
retriever: modernSCM([$class: 'GitSCMSource',
remote: "https://github.com/${env.ghprbGhRepository}",
traits: [[$class: 'jenkins.plugins.git.traits.BranchDiscoveryTrait'],
[$class: 'RefSpecsSCMSourceTrait',
templates: [[value: '+refs/heads/*:refs/remotes/@{remote}/*'],
[value: '+refs/pull/*:refs/remotes/origin/pr/*']]]]])
properties([
buildDiscarder(logRotator(artifactNumToKeepStr: '20', numToKeepStr: '20')),
[$class: 'GithubProjectProperty', displayName: '', projectUrlStr: 'https://github.com/CentOS-PaaS-SIG/upstream-fedora-pipeline/'],
[$class: 'org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty', triggers:[
[
$class: 'org.jenkinsci.plugins.ghprb.GhprbTrigger',
orgslist: 'CentOS-PaaS-SIG',
cron: 'H/5 * * * *',
triggerPhrase: '.*\\[test\\].*',
onlyTriggerPhrase: false,
useGitHubHooks: true,
permitAll: true,
autoCloseFailedPullRequests: false,
displayBuildErrorsOnDownstreamBuilds: true,
extensions: [
[
$class: 'org.jenkinsci.plugins.ghprb.extensions.status.GhprbSimpleStatus',
commitStatusContext: 'Stage Job',
showMatrixStatus: false,
triggeredStatus: 'Starting job...',
startedStatus: 'Building...',
]
]
]
]]
])}
pipeline {
agent {
kubernetes {
cloud 'openshift'
label 'stage-trigger-' + env.ghprbActualCommit
containerTemplate {
alwaysPullImage true
name 'jnlp'
args '${computer.jnlpmac} ${computer.name}'
image DOCKER_REPO_URL + '/' + openshiftProject + '/jenkins-fedoraci-slave:' + STABLE_LABEL
ttyEnabled false
command ''
}
}
}
stages {
stage("Get Changelog") {
steps {
node('master') {
script {
echo "PR number is: ${env.ghprbPullId}"
env.changeLogStr = contraUtils.getChangeLogFromCurrentBuild()
echo env.changeLogStr
}
writeFile file: 'changelog.txt', text: env.changeLogStr
archiveArtifacts allowEmptyArchive: true, artifacts: 'changelog.txt'
}
}
}
stage("Setup Container Templates") {
steps {
script {
sh """
oc whoami
"""
packagepipelineUtils.setupContainerTemplates(openshiftProject)
}
}
}
stage("jenkins-fedoraci-slave image build") {
when {
// Only build if we have related files in changeset
changeset "config/s2i/jenkins/slave/**"
}
steps {
script {
buildOpenShiftImage(openshiftProject: openshiftProject,
buildConfig: "jenkins-fedoraci-slave",
tag: "PR-" + env.ghprbPullId,
pullId: env.ghprbPullId)
tagMap['jenkins-fedoraci-slave'] = "PR-" + env.ghprbPullId
}
}
}
stage("fedoraci-runner image build") {
when {
// Only build if we have related files in changeset
changeset "config/Dockerfiles/fedoraci-runner/**"
}
steps {
script {
buildOpenShiftImage(openshiftProject: openshiftProject,
buildConfig: "fedoraci-runner",
tag: "PR-" + env.ghprbPullId,
pullId: env.ghprbPullId)
tagMap['fedoraci-runner'] = "PR-" + env.ghprbPullId
}
}
}
stage("Image Tag Report") {
steps {
script {
// Use tags derived from above image builds
//
packagepipelineUtils.printLabelMap(tagMap)
}
}
}
stage("rawhide run stage job") {
failFast false
steps {
sleep 30
build job: 'fedora-rawhide-stage-pr-pipeline',
parameters: [
string(name: 'CI_MESSAGE',
value: CANNED_CI_MESSAGES['rawhide']),
string(name: 'ghprbActualCommit',
value: "${env.ghprbActualCommit}"),
string(name: 'ghprbGhRepository',
value: "${env.ghprbGhRepository}"),
string(name: 'ghprbPullAuthorLogin',
value: "${env.ghprbPullAuthorLogin}"),
string(name: 'sha1',
value: "${env.sha1}"),
string(name: 'ghprbPullId',
value: "${env.ghprbPullId}"),
string(name: 'SLAVE_TAG',
value: tagMap['jenkins-fedoraci-slave']),
string(name: 'FEDORACI_RUNNER_TAG',
value: tagMap['fedoraci-runner']),
string(name: 'pipelineId',
value: UUID.randomUUID().toString())
],
wait: true
}
}
}
post {
always {
script {
String prMsg = ""
if (env.ghprbActualCommit != null && env.ghprbActualCommit != "master") {
prMsg = "(PR #${env.ghprbPullId} ${env.ghprbPullAuthorLogin})"
}
def message = "${JOB_NAME} ${prMsg} build #${BUILD_NUMBER}: ${currentBuild.currentResult}: ${BUILD_URL}"
contraUtils.sendIRCNotification("${IRC_NICK}-${UUID.randomUUID()}", IRC_CHANNEL, message)
}
}
success {
echo "yay!"
}
failure {
error "build failed!"
}
}
}