forked from ricardozanini/cicd-rest-app-ocp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
promote-prd.groovy
46 lines (45 loc) · 2.02 KB
/
promote-prd.groovy
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
def tagVersion = ""
def tagsInput = []
pipeline {
agent any
stages {
stage ("Grab available image versions") {
steps {
script {
openshift.withCluster() {
openshift.withProject("${env.PROJECT_NAME}-stg") {
def isTags = openshift.selector('istag', [ app: env.APP_NAME ]).objects()
for (obj in isTags) {
if (obj.tag.name.indexOf("v") >= 0) {
tagsInput.add(obj.tag.name)
}
}
}
}
}
}
}
stage ("Promote to Production") {
agent none
steps {
timeout(time:60, unit:'MINUTES') {
script {
tagVersion = input (id: 'inputTags', message: 'Which version to promote to production?', parameters: [ [$class: 'ChoiceParameterDefinition', choices: tagsInput, description: 'Choose the tag to be promoted', name: 'tag'] ])
echo "The version choosen is ${tagVersion}"
def prdTagVersion = tagVersion.substring(0, tagVersion.indexOf("-"))
openshift.withCluster() {
openshift.withProject("${env.PROJECT_NAME}-prd") {
//from dev to stg
openshift.tag("", "${env.PROJECT_NAME}-stg/${env.APP_NAME}:${tagVersion}", "${env.APP_NAME}:${prdTagVersion}")
openshift.tag("", "${env.APP_NAME}:${prdTagVersion}", "${env.APP_NAME}:latest")
//the dc should trigger
def dc = openshift.selector("dc", env.APP_NAME)
dc.rollout().status()
}
}
}
}
}
}
}
}