This repository has been archived by the owner on Mar 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile-ci-merge
81 lines (74 loc) · 3.17 KB
/
Jenkinsfile-ci-merge
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
// Openshift project
openshiftProject = "continuous-infra"
DOCKER_REPO_URL = '172.30.254.79:5000'
STABLE_LABEL = "stable"
env.ghprbActualCommit = env.ghprbActualCommit ?: 'master'
// Add new images here
imageList = ["cvengine"]
imageOperations = []
library identifier: "ci-pipeline@master",
retriever: modernSCM([$class: 'GitSCMSource',
remote: "https://github.com/CentOS-Paas-SIG/ci-pipeline"])
pipeline {
agent {
kubernetes {
cloud 'openshift'
label 'cvengine-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)
}
}
}
}
}
}