This repository has been archived by the owner on Sep 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathImageLatest
145 lines (135 loc) · 6.82 KB
/
ImageLatest
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
#!groovy
/**
* Bring Image Up To Latest
*
* This is a declarative pipeline that rebuilds the specific container image
* and promote it to stable tag
*
*/
// Openshift project
openshiftProject = "continuous-infra"
DOCKER_REPO_URL = '172.30.254.79:5000'
// If this PR does not include an image change, then use this tag
STABLE_LABEL = "stable"
tagMap = [:]
// Initialize
tagMap['fedoraci-runner'] = STABLE_LABEL
tagMap['jenkins-fedoraci-slave'] = 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"}'
// Get upstream libraries
def libraries = ['contra-lib' : ['master', 'https://github.com/openshift/contra-lib'],
'upstream-fedora-pipeline' : ['master', 'https://github.com/CentOS-PaaS-SIG/upstream-fedora-pipeline.git']]
libraries.each { name, repo ->
library identifier: "${name}@${repo[0]}",
retriever: modernSCM([$class: 'GitSCMSource',
remote: repo[1]])
}
properties(
[
parameters(
[
string(name: 'IMAGE_NAME',
defaultValue: 'fedoraci-runner',
description: 'Name of container image to build')
]
)
]
)
pipeline {
agent {
kubernetes {
cloud 'openshift'
label "image-latest-${UUID.randomUUID().toString()}"
containerTemplate {
alwaysPullImage true
name 'jnlp'
args '${computer.jnlpmac} ${computer.name}'
image DOCKER_REPO_URL + '/' + openshiftProject + '/jenkins-fedoraci-slave:' + STABLE_LABEL
ttyEnabled false
command ''
}
}
}
options {
buildDiscarder(logRotator(numToKeepStr:'5'))
timestamps()
}
stages {
stage("Setup Container Templates") {
steps {
script {
sh """
oc whoami
"""
packagepipelineUtils.setupContainerTemplates(openshiftProject)
}
}
}
stage("image build") {
steps {
script {
buildOpenShiftImage(openshiftProject: openshiftProject,
buildConfig: env.IMAGE_NAME,
tag: "stable-candidate")
tagMap[env.IMAGE_NAME] = "stable-candidate"
}
}
}
stage("Image Tag Report") {
steps {
script {
// Use tags derived from above image builds
packagepipelineUtils.printLabelMap(tagMap)
}
}
}
// See if the latest git source works for the fedora pipeline
stage("Run Stage Job") {
failFast false
parallel {
stage("fedora-rawhide-stage-pr-pipeline job") {
steps {
build job: 'fedora-rawhide-stage-pr-pipeline',
parameters: [
string(name: 'CI_MESSAGE',
value: CANNED_CI_MESSAGES['rawhide']),
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
}
}
}
}
// If the container passed stage, we can promote the stable tag
stage("promote container") {
steps {
// lock to make sure only one is allowed at anytime
lock('container-image-promotion-lock') {
script {
openshift.withCluster() {
openshift.withProject(openshiftProject) {
openshift.tag("${openshiftProject}/${env.IMAGE_NAME}:${tagMap[env.IMAGE_NAME]}",
"${openshiftProject}/${env.IMAGE_NAME}:stable")
}
}
}
}
}
}
}
post {
success {
echo "${env.IMAGE_NAME}'s stable tag promoted to latest git source"
}
failure {
echo "build failed, so ${env.IMAGE_NAME} container's stable tag not modified"
}
}
}