forked from CentOS-PaaS-SIG/ci-pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JenkinsfileStageMerge
114 lines (106 loc) · 4.74 KB
/
JenkinsfileStageMerge
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
// Openshift project
openshiftProject = "continuous-infra"
DOCKER_REPO_URL = '172.30.254.79:5000'
STABLE_LABEL = "stable"
// Defaults for SCM operations
env.ghprbGhRepository = env.ghprbGhRepository ?: 'CentOS-PaaS-SIG/ci-pipeline'
env.ghprbActualCommit = env.ghprbActualCommit ?: 'master'
// Add new images here
imageList = ["jenkins-continuous-infra-slave", "rpmbuild", "ostree-compose", "ostree-image-compose", "rsync", "singlehost-test", "ostree-boot-image", "linchpin-libvirt"]
imageOperations = []
library identifier: "ci-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/ci-pipeline/'],
[$class: 'org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty', triggers:[
[
$class: 'org.jenkinsci.plugins.ghprb.GhprbTrigger',
orgslist: 'CentOS-PaaS-SIG',
cron: 'H/5 * * * *',
triggerPhrase: '.*\\[merge\\].*',
onlyTriggerPhrase: true,
useGitHubHooks: true,
permitAll: true,
autoCloseFailedPullRequests: false,
displayBuildErrorsOnDownstreamBuilds: true,
extensions: [
[
$class: 'org.jenkinsci.plugins.ghprb.extensions.status.GhprbSimpleStatus',
commitStatusContext: 'Merge PR',
showMatrixStatus: false,
triggeredStatus: 'Starting job...',
startedStatus: 'merging...',
]
]
]
]]
])
pipeline {
agent {
kubernetes {
cloud 'openshift'
label 'merge-trigger-' + env.ghprbActualCommit
containerTemplate {
name 'jnlp'
args '${computer.jnlpmac} ${computer.name}'
image DOCKER_REPO_URL + '/' + openshiftProject + '/jenkins-continuous-infra-slave:' + STABLE_LABEL
ttyEnabled false
command ''
}
}
}
stages {
stage("Detect Images to Promote") {
steps {
script {
openshift.withCluster() {
openshift.withProject(openshiftProject) {
imageList.each {
String tagList = sh(
script: "oc get is -n ${openshiftProject} -o=jsonpath=\'{.items[?(@.metadata.name==\"${it}\")].status.tags[*].tag}\'",
returnStdout: true
).trim()
def prTag = tagList.tokenize(' ').find { it == "PR-" + env.ghprbPullId }
if (prTag != null) {
echo "Found PR tag: " + prTag + " for image ${it}"
imageOperations.add(it)
} else {
echo "No tag found for image ${it}!"
}
}
}
}
}
}
}
stage("Merge PR and Rebuild Images") {
steps {
// lock to make sure only one is allowed at anytime
lock('merge-and-image-rebuild-lock') {
script {
// need this for ghprb plugin since it is really
// a post build step and it assumes the build is complete.
currentBuild.result = 'SUCCESS'
}
step([$class: 'GhprbPullRequestMerge', allowMergeWithoutTriggerPhrase: false, deleteOnMerge: false, disallowOwnCode: false, failOnNonMerge: false, mergeComment: ' ', onlyAdminsMerge: false])
script {
openshift.withCluster() {
openshift.withProject(openshiftProject) {
imageOperations.each {
pipelineUtils.buildStableImage(openshiftProject, it)
}
}
}
pipelineUtils.sendPRCommentforTags(imageOperations)
}
}
}
}
}
}